kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

[BUG] Kvrocks SCAN does not match with Redis SCAN

Open VictorCam opened this issue 3 years ago • 5 comments

Describe the bug Scanning on Kvrocks produces incorrect responses when compared to Redis.

image image

To Reproduce Steps to reproduce the behavior:

  1. run docker
  2. get images "docker pull redis" and "docker pull kvrocks/kvrocks"
  3. "docker run --rm -d -p 6666:6666/tcp kvrocks/kvrocks:latest"
  4. "docker run --rm -d -p 6379:6379/tcp redis:latest"
  5. open two redis-cli instances one on port 6739 and 6666
  6. set "hi" and set "hello there" on both instances
  7. 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 avatar Apr 12 '22 01:04 VictorCam

@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.

ShooterIT avatar Apr 12 '22 01:04 ShooterIT

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.

VictorCam avatar Apr 12 '22 01:04 VictorCam

and if you are curious, we maintain a fork of the Redis Python library to make the iterator works on kvrocks.

adulau avatar Apr 29 '22 11:04 adulau

@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".

tisonkun avatar May 15 '22 07:05 tisonkun

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.

tisonkun avatar May 15 '22 07:05 tisonkun

See #1489.

PragmaTwice avatar Jun 25 '23 16:06 PragmaTwice