redis / hiredis

Minimalistic C client for Redis >= 1.2
BSD 3-Clause "New" or "Revised" License
6.22k stars 1.81k forks source link

support REDIS_REPLY_EMPTY_ARRAY as a new return type. #1241

Closed mmaatuq closed 9 months ago

mmaatuq commented 10 months ago

In case of hgetall where key doesn't exist, there is an empty array, isn't it more convenient to add a new return type for this instead of array type with elements = 0. It could be equivalent to NIL in case of get command.

michael-grunder commented 10 months ago

What's your thinking behind that?

Due to Redis semantics, an empty array (RESP2) or an empty map (RESP3) convey to the caller that the key does not exist, as Redis does not store zero length keys.

how would the new type be useful?

mmaatuq commented 9 months ago

thanks for your reply @michael-grunder I know it's not an issue, it's about convenience, so instead of checking the reply->type == REDIS_REPLY_ARRAY and then check if reply->elements == 0 to decide if the key exists, we could decide that the key doesn't exist if we added this new return type REDIS_REPY_EMPTY_ARRAY.

michael-grunder commented 9 months ago

I can see where you're coming from but unfortunately we can't actually change this as it would be a massive breaking change (also Redis would need to be changed as well).

What I would suggest is doing this check in your app in a convenience function.