redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.31k stars 1.19k forks source link

The COUNT param in SCAN command #1815

Open LeyiMoo opened 1 year ago

LeyiMoo commented 1 year ago

Hi there,

I tried to search the documentation around but couldn't really find the definition for COUNT below.

SCAN cursor [MATCH pattern] [COUNT count] [TYPE type]

While implementing the real js code, I found a more basic language to represent my confusion as below.

Let's say I have set two keys:

localhost:6384> SET prefix::key2::hello "Hello"
OK
localhost:6384> SET prefix::key1::hello "Hi"
OK

Why the number after COUNT would affect the result?

localhost:6384> SCAN '0' MATCH prefix::*key* COUNT 100
1) "198"
2) 1) "prefix::key2::hello"

localhost:6384> SCAN '0' MATCH prefix::*key* COUNT 10000
1) "0"
2) 1) "prefix::key2::hello"
   2) "prefix::key1::hello"

localhost:6384> SCAN '0' MATCH prefix::*key* COUNT 1
1) "64"
2) (empty array)

From what I can see, count as 100 will:

// returns approximately 100 elements per call

But why does that have an impact on the results of scanning - as well as the cursor at this point? This has confused me for a long time...

Appreciate anyone who has answers to my questions and welcome any open discussion.

Thank you!