I have understood the meaning of COUNT in the case of REDIS SCAN. But, what is the ideal value for REDIS COUNT ?
相关问题
- Getting Redis Master address from Sentinel C#
- Configuring Redis to play nice with AppHarbor
- Why do we need Redis for running CKAN?
- Problem in deserialize redis-cache to objects in S
- wait for all promises to finish in nodejs with blu
The default value is
10
. It means the command will bring back more or less 10 keys, could be less if the keys are sparsely populated in the hash slots, or filtered out by theMATCH
pattern. It could be more if some keys are sharing a hash slot. Anyhow, the work performed is proportional to theCOUNT
parameter.Redis is single-threaded. One of the reasons
SCAN
was introduced is to allow going through all the keys without blocking the server for a long time, by going a few steps at a time.And that's precisely the criteria to decide what's a good number. For how long are you willing to block your Redis server by running a
SCAN
command. The higher theCOUNT
, the longer the block.Let's use a Lua script to get a sense of the
COUNT
impact. Use it on your environment to get the results based on your server resources.The Lua script:
Here we use Redis
TIME
command. The command returns:A few runs in my machine, with 1 million keys:
Note these times don't include the time used to read from the socket and to buffer and send the response. Actual times will be larger. The time it takes once is out of Redis, including time traveling the network is not time your Redis server is blocked though.
This is how I called the Lua script and the results: