Describe the bug

When using RESP 3, the HKEYS command returns an empty hash when a key doesn't exist, but an array when it does exist.

To reproduce

Using redis-cli:

127.0.0.1:6379> HELLO 3
1# "server" => "redis"
2# "version" => "6.0.5"
3# "proto" => (integer) 3
4# "id" => (integer) 4
5# "mode" => "standalone"
6# "role" => "master"
7# "modules" => (empty array)
127.0.0.1:6379> HKEYS test_nonexistent_key
(empty hash)

Expected behavior

I expected the return type to be consistent with the type received when the key does exist (array). Although, I also think that a set might be more appropriate as a return type here.

Comment From: itamarhaber

Hello @Harrison88

Thanks for reporting this - I can verify this happens, and I concur that this (empty hash) may not be the ideal response type in this case. HVALS appears to be misbehaving in the same respect as well.

@eliblight please feel free to take a look at this if you want.

Comment From: madolson

If anyone else wants to look into it, I think the problematic line is here: https://github.com/redis/redis/blob/unstable/src/t_hash.c#L769

Where we always return the empty hash even though we would expect an array if (flags & OBJ_HASH_KEY && flags & OBJ_HASH_VALUE) evaluates to false.

edit: I also did a quick audit to check for any other obvious misuses of this, and I didn't find any.