Fix Redis Iterators (#318)
Redis SCAN may return same item multiple times, add a basic check to avoid duplicate entries.
This commit is contained in:
parent
f58bb3e41d
commit
8a4151f397
@ -151,12 +151,12 @@ func (client *Client) Iterate(opts storage.IterateOptions, fn func(it storage.It
|
||||
|
||||
func (client *Client) allPrefixedItems(prefix, first, last storage.Key) (storage.Items, error) {
|
||||
var all storage.Items
|
||||
seen := map[string]struct{}{}
|
||||
|
||||
match := string(escapeMatch([]byte(prefix))) + "*"
|
||||
it := client.db.Scan(0, match, 0).Iterator()
|
||||
for it.Next() {
|
||||
key := it.Val()
|
||||
|
||||
if first != nil && storage.Key(key).Less(first) {
|
||||
continue
|
||||
}
|
||||
@ -164,6 +164,11 @@ func (client *Client) allPrefixedItems(prefix, first, last storage.Key) (storage
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := seen[key]; ok {
|
||||
continue
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
|
||||
value, err := client.db.Get(key).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user