Since these commands allow for incremental iteration, returning only a
small number of elements per call, they can be used in production
without the downside of commands like KEYS or SMEMBERS that may block
the server for a long time (even several seconds) when called against
big collections of keys or elements.
However while blocking commands like SMEMBERS are able to provide all the elements that are part of a Set in a given moment, The SCAN family of commands only offer limited guarantees about the returned elements since the collection that we incrementally iterate can change during the iteration process.
The default COUNT value is 10.
When iterating the key space, or a Set, Hash or Sorted Set that is big
enough to be represented by a hash table, assuming no MATCH option is
used, the server will usually return count or a bit more than count
elements per call.
When iterating Sets encoded as intsets (small sets composed of just
integers), or Hashes and Sorted Sets encoded as ziplists (small hashes
and sets composed of small individual values), usually all the elements
are returned in the first SCAN call regardless of the COUNT value.
key = 'table_key'
cur = 0
while True:
cur, ret = redis.SOME_TABLE.sscan(key, cursor=cur, count=100)
# some code deal with ret
if cur == 0:
return