Redis Key Scan not always returning all the values

4/12/2019

I have an issue where my Redis key SCAN (with a wildcard) does not appear to consistently be returning all the values. It works correctly many times but not all the time. Maybe I don't understand how scan is supposed to work. I am using redigo as my library.

Pattern to match with Wildcard:

  • "event.query.zt2qXIVY80fCTbmWf3sbC5QaoTg2*"

Keys In Redis:

  • event.query.zt2qXIVY80fCTbmWf3sbC5QaoTg2?DateRange2019-04-12-2019-04-17
  • event.query.zt2qXIVY80fCTbmWf3sbC5QaoTg2?DateRange2019-04-13-2019-04-13
  • event.query.zt2qXIVY80fCTbmWf3sbC5QaoTg2?DateRange2019-04-08-2019-04-14
  • event.query.zt2qXIVY80fCTbmWf3sbC5QaoTg2?DateRange2019-04-12-2019-04-12

I am basically looking for any keys from that GUID but the matching seems inconsistent. Here is my code that I am using to pattern match.

//GetKeysFromPattern - The endpoint to retrieve a list of keys that match a pattern
func GetKeysFromPattern(pattern string) ([]string, error) {
    tempConn := pool.Get()
    defer tempConn.Close()
    if tempConn.Err() == nil {
        iter := 0
        keys := []string{}
        for {
            arr, err := redis.Values(tempConn.Do("SCAN", iter, "MATCH", pattern))
            if err != nil {
                return keys, fmt.Errorf("error retrieving '%s' keys", pattern)
            }
            iter, _ = redis.Int(arr[0], nil)
            k, _ := redis.Strings(arr[1], nil)
            keys = append(keys, k...)
            if iter == 0 {
                break
            }
        }
        return keys, nil
    }
    return nil, sharedstructs.InternalServerError{Msg: "No Connection To Redis So Returning nil"}
}
-- mornindew
go
google-kubernetes-engine
redigo
redis

0 Answers