redis-rb: Redis::exists should no longer use Boolify
In the Redis documentation for exists, as of Redis 3.0.3 exists may take multiple key names and returns a count of the number of keys that exist.
Using the redis-rb gem v3.3.3, the result of Redis::exists with an array of keys returns true if and only if just one of the keys exist. false is returned if none of the keys exist or if multiple keys do because Boolify looks for a non-nil value equal to 1.
To reproduce:
r = Redis.new
r.mset 'test1', 1, 'test2', 2
r.exists ['test1', 'nonexistant']
#=> true
r.exists ['test1', 'test2']
#=> false
So either Boolify could be adjusted to look for values >= 1, or (what makes more sense to me) Boolify should not be used in this function so that the return value is the count of the number of keys found as is described in the Redis docs.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 19 (7 by maintainers)
Commits related to this issue
- Change #exist behaviour for enumerables #698 — committed to ybinzu/redis-rb by ybinzu 7 years ago
- Update non-distributed `exists` command to accept multiple keys supported since Redis 3.0.3. Fix redis/redis-rb/#698 — committed to kumekay/redis-rb by kumekay 6 years ago
If there is a real demand for number of existed keys, it can be implemented as separate method,
exists_count, for exampleThe issue was originally raised because commands in the gem generally follow the Redis documentation for identically named commands, but in this case, the
redis-rbgem departs from Redis behavior. This creates a barrier to use (admittedly small).I raised the issue with the hope that a resolution would bring the gem’s behavior back into alignment with the Redis documentation. I think only one or two of the proposed solutions have attempted to resolve the issue with this goal in mind. But to me, those seem like the best solutions. It will create minor issues for existing users, but will make the gem more intuitive and prevent confusion for new users.