Open rafak opened 1 year ago
The reply is either 0
or 1
, the server replies with an integer and not a boolean because RESP2 does support booleans..I think converting the reply to a boolean is more convenient.. @chayim @guyroyse @itamarhaber WDUT?
I think converting the reply to a boolean is more convenient
just a note on that from the perspective of a person using the library:
it can be whatever but i would suggest explicitly adding this to the documentation - that the response from node-redis
differs from the response from redis itself and also add it to the migration guide as the previous behavior was different
I agree with @leibale. If it returned a number I would just convert it to a boolean in my code. (‼️) This is a convenience in the same way that hGetAll
returning JavaScript objects instead of an array of strings as the Redis documentation states is a convenience.
That said, is there any chance that Redis might decide to return something more than just 0 or 1? Is there some other state that might be useful here? I'm thinking like how TTL used to return -1 if a key was persistent or didn't exists but then changed to be -2 if it didn't exists and -1 if it existed but was persistent. If so, a boolean would lock us in to a particular pattern that would be a pain to escape.
I don't see EXPIRE
's return value being overloaded with -1 in the future, but anything could happen. Also, note that in RESP3 we still use an integer rather than a Boolean. As much as I like this convenience (casting 0/1 to bool) it feels brittle in terms of not being totally future-proof.
I'm very much on board with the client returning a boolean to replace 0/1 when things should be a boolean ideally (i.e EXPIRE), and the fact that RESP2 (and Redis 1.0.0 in this case) didn't have another answer.
We need to consider this API (on the redis side) broken anyways. Let's assume that the reason to maintain this integer use case, is a potential future multi key response. Well, we run into the following:
The result means that I, as a user have more work to do either way. Hence, voting boolean. I believe commands of this nature are already broken for multikey and may argue that this is equally as future problematic, but at least more user friendy.
I think boolean is fine, but not quite for the reason @chayim states. I don't think EXPIRE can ever be multikey, I'd think we would have an MEXPIRE that is multi key, which would then have a different API.
if it were me, I'd update the redis command documentation to say that it returns an integer reply with the boolean values of 0 and 1. emphasis to add the boolean word, to make it clear that it will only ever be 0 or 1). Any other use case should be handled via an error response.
Redis docs for the EXPIRE command state that it returns an "Integer reply"
in node-redis the response is transformed into a boolean.
Environment: