Is SCAN a non-blocking operation?

1,114 views
Skip to first unread message

John Lee

unread,
Jul 27, 2014, 3:33:30 PM7/27/14
to redi...@googlegroups.com
Hi all,

From what I've read before, it appears to be non-blocking, but I want to double check:

If I run a pattern SCAN command through millions of keys (in which a quarter of the keys may match the pattern), then other operations being run through redis won't be affected at all? Will it limit the maximum throughput of operations per second? 

Thanks,
J

Jan-Erik Rediger

unread,
Jul 27, 2014, 3:47:31 PM7/27/14
to redi...@googlegroups.com
You're right: It is non-blocking. All state of a SCAN operation is saved
in the "cursor" value, which starts at 0 and is also returned by each
call.
Thus no internal data is stored and no other commands are affected. It
shouldn't affect throughput of other operations (of course if you
frequently execute SCAN this will count for the total number of
operations as well)
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.

Josiah Carlson

unread,
Jul 28, 2014, 5:41:59 PM7/28/14
to redi...@googlegroups.com, Jan-Erik Rediger
To correct/redirect - SCAN is a blocking command, but it only blocks during its execution. This usually isn't a big deal, especially if you do not use the COUNT argument (which defaults to 10), but if you use a COUNT argument, Redis will block other commands from executing until the number of items is at least the count provided (or it has exhausted the keyspace during the scan, whichever comes first). If you use a count of 1 million, and your hash is big enough, you may have to wait for Redis to scan 1 million keys before letting other commands execute.

So yes, SCAN is blocking, but it's usually not a big deal, and is only blocking when Redis is actually processing the command. Omit the COUNT and MATCH arguments, and it's probably not an issue. Whether it becomes an issue after adding MATCH and/or COUNT arguments will depend on your data and your use of SCAN.

 - Josiah
Reply all
Reply to author
Forward
0 new messages