Redis scan returns nothing

282 views
Skip to first unread message

Mehdi 343

unread,
Aug 25, 2023, 9:55:27 AM8/25/23
to Redis DB
Hi everybody. Can someone explain me why is this happen?

Greg Andrews

unread,
Aug 25, 2023, 12:40:52 PM8/25/23
to Redis DB
The answer that was posted to that stackoverflow question says:
  • A single SCAN command is not guaranteed to give you any keys, even if you pass `count=5` to it.
  • Since an individual SCAN command can return empty results, you must invoke SCAN repeatedly, saving the key list that's returned by each invocation, looping until it returns the "next cursor" value of 0.  This is also outlined in the Redio.IO documentation for SCAN.
Your example code in the question isn't calling SCAN in a loop and checking the cursor value returned by the command.  It's only calling SCAN once, which is not guaranteed to give you the list of existing keys.
Reply all
Reply to author
Forward
0 new messages