dice icon indicating copy to clipboard operation
dice copied to clipboard

Inconsistent `MSET`: Handling of Binary Keys Differs Between DiceDB and Redis

Open arbha1erao opened this issue 1 year ago • 12 comments

The command MSET is not consistent with Redis implementation. Here are the steps to reproduce the issue

Execute Command - MSET key value (Where key is an binary data) Excute Command - GET key

Here's the output I observed in Redis v7.2.5

# On Redis v7.2.5:
127.0.0.1:6379> MSET "\x00\x01\x02" "value"
OK
127.0.0.1:6379> get \x00\x01\x02
(nil)
127.0.0.1:6379> get "\x00\x01\x02"
"value"

and here's the output I observed in DiceDB's latest commit of the master branch

# On DiceDB:
127.0.0.1:7379> MSET "\x00\x01\x02" "value"
OK
127.0.0.1:7379> get \x00\x01\x02
"value"
127.0.0.1:7379> get "\x00\x01\x02"
"value"

(Observe the value printed by GET in absense of double-quotes)

To summarize -

  • In DiceDB, both the raw binary key (\x00\x01\x02) and the escaped string representation ("\x00\x01\x02") retrieve the value correctly.
  • In Redis, the raw binary key (\x00\x01\x02) returns (nil), while the escaped string version ("\x00\x01\x02") correctly retrieves the value.

Make the implementation consistent with the Redis implementation. Make sure you are using Redis version 7.2.5 as a reference for the command implementation and to setup Redis

arbha1erao avatar Sep 09 '24 16:09 arbha1erao

Hi @arpitbbhayani I would like to work on this issue.

swarajrb7 avatar Sep 09 '24 16:09 swarajrb7

I came across this issue while working on https://github.com/DiceDB/dice/issues/378

cc: @JyotinderSingh

arbha1erao avatar Sep 09 '24 16:09 arbha1erao

@swarajrb7 go for it. Thanks for picking it up!

AshwinKul28 avatar Sep 09 '24 16:09 AshwinKul28

Few more additions to this -

This is occurring with SET command as well.

# On DiceDB
127.0.0.1:7379> SET "\x00\x01" "value"
OK
127.0.0.1:7379> get "\x00\x01"
"value"
127.0.0.1:7379> get \x00\x01
"value"
# On Redis
127.0.0.1:6379> SET "\x00\x01" "value"
OK
127.0.0.1:6379> get "\x00\x01"
"value"
127.0.0.1:6379> get \x00\x01
(nil)

arbha1erao avatar Sep 09 '24 16:09 arbha1erao

In Redis, the key is treated as a binary-safe string, while DiceDB seems to be interpreting unquoted binary sequences as valid keys, leading to the discrepancy. Redis used RESP(Redis Serialization Protocol). In RESP, strings are represented as a $ character, followed by the length of the string in decimal format, followed by \r\n. The string itself can contain arbitrary characters including \0, \r and \n and can hence be used to represent binary blobs

swarajrb7 avatar Sep 14 '24 18:09 swarajrb7

Hello might not be able to work on this. Can we un-assign me so that we have someone else pick this up for now? @arpitbbhayani / @AshwinKul28

swarajrb7 avatar Sep 19 '24 17:09 swarajrb7

@AshwinKul28 - I can pick this up.

psrvere avatar Sep 19 '24 17:09 psrvere

Could not able to reproduce this in the master branch as of today.

image

btalukdar511 avatar Sep 21 '24 00:09 btalukdar511

@btalukdar511, I am still able to reproduce.

REDIS

image

DICE

image

arbha1erao avatar Sep 21 '24 08:09 arbha1erao

Hi @arpitbbhayani can i take this up

kabi175 avatar Oct 04 '24 17:10 kabi175

@Aditya-Bhalerao @arpitbbhayani can you please assign this to me

kaustubhdeokar avatar Oct 08 '24 15:10 kaustubhdeokar

@arpitbbhayani @apoorvyadav1111 Can I take this up?

kaushal-003 avatar Dec 02 '24 16:12 kaushal-003