DiceDB / dice

DiceDB is an in-memory real-time database with SQL-based reactivity. It is hyper-optimized for building and scaling truly real-time applications on modern hardware while being a drop-in replacement for Redis.
https://dicedb.io/
Other
4.2k stars 520 forks source link

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

Open Aditya-Bhalerao opened 1 week ago

Aditya-Bhalerao commented 1 week ago

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 -

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

swarajrb7 commented 1 week ago

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

Aditya-Bhalerao commented 1 week ago

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

cc: @JyotinderSingh

AshwinKul28 commented 1 week ago

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

Aditya-Bhalerao commented 1 week ago

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)
swarajrb7 commented 3 days ago

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.