Skip to content

Instantly share code, notes, and snippets.

@JeffreyCA
Last active August 5, 2020 18:49
Show Gist options
  • Save JeffreyCA/e16774ada8c4ee90877734f89892b274 to your computer and use it in GitHub Desktop.
Save JeffreyCA/e16774ada8c4ee90877734f89892b274 to your computer and use it in GitHub Desktop.
Redis duplicate key issue when doing a SCAN

Here's how to reproduce a scenario when the same key may be returned during a continuous SCAN.
A detailed explanation: https://groups.google.com/d/msg/redis-db/2V5x4-MOOEk/jNDUY11AEZYJ

> flushdb

OK

> mset 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18

OK

> scan 0 count 3
  1. "28"
    1. "6"
    2. "17"
    3. "5"
> scan 28 count 3
  1. "6"
    1. "12"
    2. "10"
    3. "11"
    4. "15"
> scan 6 count 3
  1. "29"
    1. "14"
    2. "7"
    3. "2" <----- dupe
    4. "3"
> del 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3

(integer) 16

> scan 29 count 3
  1. "0"
    1. "2" <----- dupe
    2. "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment