kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

Inconsistent behavior with Redis in BITFIELD GET command

Open VIVALXH opened this issue 1 year ago • 2 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Version

Docker Image SHA:707f93473e7265df39593d38d83081ec1a6a36da31c97b391008858eb45a437f

kvrocks 镜像版本:sha256:707f93473e7265df39593d38d83081ec1a6a36da31c97b391008858eb45a437f

Minimal reproduce step

  1. kvrocks设置位图01011000对应字母X: redis-cli -h 192.168.1.72 -p 6666 192.168.1.72:6666> flushdb OK 192.168.1.72:6666> SETBIT A 0 0 (integer) 0 192.168.1.72:6666> SETBIT A 1 1 (integer) 0 192.168.1.72:6666> SETBIT A 2 0 (integer) 0 192.168.1.72:6666> SETBIT A 3 1 (integer) 0 192.168.1.72:6666> SETBIT A 4 1 (integer) 0 192.168.1.72:6666> SETBIT A 5 0 (integer) 0 192.168.1.72:6666> SETBIT A 6 0 (integer) 0 192.168.1.72:6666> SETBIT A 7 0 (integer) 0 192.168.1.72:6666> GET A "X" 192.168.1.72:6666> bitfield A get u7 0
  1. (integer) 13
  1. redis设置位图01011000对应字母X: redis-cli -h 192.168.1.72 -p 6379 192.168.1.72:6379> flushdb OK 192.168.1.72:6379> SETBIT A 0 0 (integer) 0 192.168.1.72:6379> SETBIT A 1 1 (integer) 0 192.168.1.72:6379> SETBIT A 2 0 (integer) 0 192.168.1.72:6379> SETBIT A 3 1 (integer) 0 192.168.1.72:6379> SETBIT A 4 1 (integer) 0 192.168.1.72:6379> SETBIT A 5 0 (integer) 0 192.168.1.72:6379> SETBIT A 6 0 (integer) 0 192.168.1.72:6379> SETBIT A 7 0 (integer) 0 192.168.1.72:6379> GET A "X" 192.168.1.72:6379> bitfield A get u7 0
  1. (integer) 44

What did you expect to see?

设置位图01011000对应字母X,通过bitfield从0偏移量获取7位,kvrocks结果是13(0001101),redis是44(0101100),从bitfield定义中,预期应该是redis对应的结果。

What did you see instead?

Anything Else?

No response

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR!

VIVALXH avatar Aug 21 '24 03:08 VIVALXH

Will check this later today

mapleFU avatar Aug 21 '24 03:08 mapleFU

kvrocks bitmap uses LSB here, and MSB is used in redis...This is the root cause of this problem

I would try to fix the bitfield, but "get" would not gurantee to be same as redis.

mapleFU avatar Aug 21 '24 13:08 mapleFU