dragonflydb / dragonfly

A modern replacement for Redis and Memcached
https://www.dragonflydb.io/
Other
25.47k stars 926 forks source link

`HRANDFIELD` errors when key does not exist #1352

Closed Guillermogsjc closed 1 year ago

Guillermogsjc commented 1 year ago

Describe the bug HRANDFIELD fails when provided a key that does not exist.

In redis API it does not crash (as idiomatic), it just returns None

To Reproduce

import redis
...
redis_client.hrandfield(key, withvalues=False)

with unexisting key (maybe it is a key that existed but every field has been popped, or a directly never existing one).

Obtaining through redis==4.5.5 python SDK:

ResponseError: no such key

or from shell:

127.0.0.1:6379> HRANDFIELD "unexisting"
(error) ERR no such key

Expected behavior Not to crash, give back None, as in Redis API (just moved a workload that used to be working against redis and it is crashing at this point).

Need corner test cases of calling methods over empty/unexisting keys to match Redis API idiomatic standard (return None not fail)

127.0.0.1:6379> HRANDFIELD "unexisting"
(nil)

Screenshots

Environment (please complete the following information):

docker run --rm -p 6379:6379  docker.dragonflydb.io/dragonflydb/dragonfly
chakaz commented 1 year ago

Thanks for submitting this issue!

To clarify, what's crashing is the client that doesn't handle the error. Dragonfly wrongly returns an error instead of a null, which it shouldn't, and this the fix I had just sent.