kvrocks
kvrocks copied to clipboard
[BUG] Kvrocks SCAN does not match with Redis SCAN
Describe the bug Scanning on Kvrocks produces incorrect responses when compared to Redis.

To Reproduce Steps to reproduce the behavior:
- run docker
- get images "docker pull redis" and "docker pull kvrocks/kvrocks"
- "docker run --rm -d -p 6666:6666/tcp kvrocks/kvrocks:latest"
- "docker run --rm -d -p 6379:6379/tcp redis:latest"
- open two redis-cli instances one on port 6739 and 6666
- set "hi" and set "hello there" on both instances
- preform the same queries as shown in the image.
Expected behavior I believe scan should be the same as how redis is preforming the scan.
@VictorCam Thanks for your report there are two difference with redis, i find
- return value is string instead of integer, the reason is here https://github.com/KvrocksLabs/kvrocks/discussions/417
- From code, Kvrocks currently only support "prefix" match, so it return 0 when
match *he*, for this, we can support it i think, even it may be inefficient.
Thank you for the quick response and explanation. I'd be nice to have that implemented. I believe it can be useful in certain scenarios. Though feel free to decide if you'd like to implement it or not considering that fact that it will be inefficient.
and if you are curious, we maintain a fork of the Redis Python library to make the iterator works on kvrocks.
@ShooterIT Another concern is that on Kvrocks, SCAN return the cursor "_hello" but actually if you want to iterate on next element, it requires a number based cursor.
For example:
127.0.0.1:6666> set "hi there" v0
OK
127.0.0.1:6666> set "hello" v1
OK
127.0.0.1:6666> SCAN 0 MATCH hel* COUNT 10000
1) "_hello"
2) 1) "hello"
127.0.0.1:6666> SCAN 0 MATCH he* COUNT 10000
1) "_hello"
2) 1) "hello"
127.0.0.1:6666> SCAN 0 MATCH h* COUNT 10000
1) "_hi there"
2) 1) "hello"
2) "hi there"
127.0.0.1:6666> SCAN "_hi there" MATCH h* COUNT 10000
1) "0"
2) (empty array)
127.0.0.1:6666> SCAN "hi there" MATCH h* COUNT 10000
1) "0"
2) (empty array)
127.0.0.1:6666> SCAN 1 MATCH h* COUNT 10000
1) "_hi there"
2) 1) "hi there"
Note that SCAN "_hi there" ... returns "0".
Sorry. I get it wrong.
127.0.0.1:6666> SCAN 1 MATCH h* COUNT 1
1) "_hi there"
2) 1) "hi there"
127.0.0.1:6666> SCAN 0 MATCH h* COUNT 1
1) "_hello"
2) 1) "hello"
127.0.0.1:6666> SCAN "_hello" MATCH h* COUNT 1
1) "_hi there"
2) 1) "hi there"
The cursor should work.
See #1489.