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:
Keys In Redis:
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"}
}