-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis::exists should no longer use Boolify #698
Comments
…rted since Redis 3.0.3. Fix redis/redis-rb/redis#698
If there is a real demand for number of existed keys, it can be implemented as separate method, |
Any update on the status of this? It looks like there are three in-progress PRs for providing functionality to accept multiple keys: #728 by @ybinzu - uses Thanks to all involved and sorry for any unwanted pings |
Just ran into this issue as well. |
Because this issue was not resolved by the time I needed it to be, I just ended up writing a helper method in my class RedisClient
...
@client = Redis.new
...
def exists(keys)
res = keys.inject(0) { |key, count| count +=1 if @client.exists(key) }
res == 0 ? nil : res
end
end |
Fixed in 3257527 |
@byroot This resolution seems okay, but probably changing the return type should be a major version bump (5.0.0) as this is a breaking change (I'm referrering to the warning issued when you call |
Also this causes gems like Sidekiq to write a lot of junk to the console -- if there was a way to turn off the message that would be good. |
This should do: Redis.send(:alias_method, :exists, :exists?) |
I'd probably rather a way that was a little more future-proof :) I've reverted the minor upgrade in my codebases because it's a lot of extra logging. My suggestion would be to piggy back on the (the default value would be I'm happy to do a PR. I'd also like to know your thoughts on the major version bump; it's not backwards compatible so it seems like a major version bump is required. |
Sure, let's see how your PR look.
Semver is not gospel, and |
Semver isn't gospel, but for people like me who aren't actually using this gem directly it keeps things simpler. It's a trivial change, but this gem is a dependency of a lot of others. Who knows what their gemspecs say; I'd say it's reasonably likely that a bunch of mysterious bugs will appear if the next release comes out with it. I'd say that if |
Because you then have the exact inverse issue to the one you described. Since a lots of gem depends on The Redis 4.0 was a big pain, I don't want to repeat that for such a small change that's trivial to fix. As an aside Sidekiq literally merged the fix for it in record time: sidekiq/sidekiq#4591 it's just a matter of waiting for the release, in the meantime staying on 4.1.x version or simply setting |
Yes, that's a valid concern definitely -- I wasn't implying it was an easy situation. And yes, at least Sidekiq is an active project, so getting updates is easy. Perhaps a more conservative option would have been to make the change in 5.0 but add another method that did the multi key thing (like some of the other PRs). Anyway, my PR is there if you're interested. |
I would have preferred to see the warning only if multiple keys are passed to
This would minimize warnings and only trigger on code that is arguably using the API incorrectly. wdyt? |
@mperham until 4.2 redis-rb wasn't accepting multiple keys for One option I played with was for |
I guess I don't understand why the code should allow Arrays with |
It doesn't, it only takes variadic arguments.
Yes, several PRs proposed to offer a distinct method ( I'd much rather go through a soft deprecation. |
The issue was originally raised because commands in the gem generally follow the Redis documentation for identically named commands, but in this case, the 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. |
In the Redis documentation for
exists
, as of Redis 3.0.3exists
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 ofRedis::exists
with an array of keys returnstrue
if and only if just one of the keys exist.false
is returned if none of the keys exist or if multiple keys do becauseBoolify
looks for a non-nil value equal to 1.To reproduce:
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.The text was updated successfully, but these errors were encountered: