Skip to content
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

Fix: Redis#exists(key) Warning from redis 4.2.0 #288

Merged
merged 9 commits into from Mar 26, 2021
Merged

Fix: Redis#exists(key) Warning from redis 4.2.0 #288

merged 9 commits into from Mar 26, 2021

Conversation

MikeRogers0
Copy link
Contributor

@MikeRogers0 MikeRogers0 commented Jul 1, 2020

This fixes the deprecation warning:

Redis#exists(key) will return an Integer in redis-rb 4.3. exists? returns a boolean, you should use it instead. To opt-in to the new behavior now you can set Redis.exists_returns_integer = true. To disable this message and keep the current (boolean) behaviour of 'exists' you can set Redis.exists_returns_integer = false, but this option will be removed in 5.0. (/usr/local/bundle/gems/sidekiq-cron-1.2.0/lib/sidekiq/cron/job.rb:464:in `block in save')

Approach

I think we're safe to replace instances of Redis#exists(key) with Redis#exists?(key). It has been updated to conditionally change the method being used depending on the Redis version being used.

Try it now

Update your gemfile to use

gem 'sidekiq-cron', github: 'MikeRogers0/sidekiq-cron', branch: 'bug/fix-redis-warning'

Related Tickets

Closes #286

If you liked this PR, please consider buying me a coffee :)

@coveralls
Copy link

coveralls commented Jul 1, 2020

Coverage Status

Coverage increased (+0.02%) to 91.542% when pulling 9957edc on MikeRogers0:bug/fix-redis-warning into 7ca90f9 on ondrejbartas:master.

@iamcz
Copy link

iamcz commented Jul 21, 2020

@ondrejbartas any idea if this can make it into a patch? Any ideas on the CI? I wonder if this needs to handle multiple versions of Redis and use exists / exists? conditionally on which version is being used. It does not look like there has been any progress on the other MRs for redis-namespace.

@jspanjers
Copy link

@ondrejbartas any idea if this can make it into a patch? Any ideas on the CI? I wonder if this needs to handle multiple versions of Redis and use exists / exists? conditionally on which version is being used. It does not look like there has been any progress on the other MRs for redis-namespace.

Would it be enough to just add an explicit dependency on redis >= 4.2.0 to sidekiq-cron?

@lucascaton
Copy link

Hi @ondrejbartas! Any news on this?
Is there anything we can do to help? Thanks!

@hirowatari
Copy link

@ondrejbartas What can be done to get this completed?
It seems reasonable to me to just bump the redis dependency to at least 4.2 and cut a new gem that requires this.

I'm worried that this gem should be treated as abandoned. Is there anything we can do to help?

@swiknaba
Copy link

swiknaba commented Jan 3, 2021

exists? was only introduced to Redis with version 4.2.0 (June 09, 2020). This gem depends on redis-namespace, which allows redis >= 3.0.4.

Checking out the Travis logs, we see that using Ruby <= 2.4, we get this error:

Redis::CommandError: ERR unknown command `exists?`, with args beginning with: `testy:cron_job:nonexisting`,
    /home/travis/.rvm/gems/ruby-2.4.10/gems/redis-4.1.4/lib/redis/client.rb:126:in `call'

Since this PR now requires Redis >= 4.2 in the gemspec, this should be fine. Strange.

sidekiq-cron.gemspec Outdated Show resolved Hide resolved
sidekiq-cron.gemspec Outdated Show resolved Hide resolved
@MikeRogers0
Copy link
Contributor Author

@swiknaba - Thank you for spotting that duplication :)

My preference right now is drop support for older Ruby/RoR versions if it helps get this update in. Though I've not heard anything from @ondrejbartas :/

@ondrejbartas - Do you have a BuyMeACoffee page? I'd gladly pay a little towards to helping fix this warning :)

@fuegas
Copy link

fuegas commented Jan 4, 2021

@MikeRogers0 : If you add the following to the PR I think you can resolve the errors in the testsuite:

unless Redis.instance_methods(false).include? :exists?
  class Redis
    alias exists? exists
  end
end

or the following for a short form, though I'd prefer the one above:

class Redis
  alias exists? exists unless instance_methods(false).include? :exists?
end

@swiknaba
Copy link

swiknaba commented Jan 4, 2021

Instead of globally polluting the Redis class, we could also just pull the correct method right on the spot and make clear in the code, that this is due to a change in the Redis gem starting with version 4.2:

REDIS_EXISTS_METHOD = Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?
conn.send(REDIS_EXISTS_METHOD, job_enqueued_key)

maybe also add an Issue in either case, to remove this hack-around/monkey-patch when dropping support for Redis < 4.2 (after merging this PR).

@MikeRogers0
Copy link
Contributor Author

MikeRogers0 commented Jan 25, 2021

I added @swiknaba change in, it passed locally 🤞 travis CI passes.

I'm also going to update this PR to not change the .gemspec file as I don't think we need to change those anymore.

siccous pushed a commit to BTLzdravtech/sidekiq-cron that referenced this pull request Feb 16, 2021
Fix: Redis#exists(key) Warning from redis 4.2.0 sidekiq-cron#288
@ondrejbartas ondrejbartas merged commit 6a0aeff into sidekiq-cron:master Mar 26, 2021
@odarriba
Copy link

Thanks for solving this (and for this awesome gem ❤️ )!
Is there any plan to release a new version for this or we should wait for more changes to come?

@miks
Copy link

miks commented May 24, 2021

@ondrejbartas is it possible to get gem release? We are getting github auth problems in our build system.

@ac21
Copy link

ac21 commented Jul 27, 2021

@swiknaba @ondrejbartas - any update on this?

@swiknaba
Copy link

@swiknaba @ondrejbartas - any update on this?

I'm not a maintainer and thus, sadly, can't publish a release.

@23tux
Copy link

23tux commented Dec 10, 2021

Is there any chance, that a new release gets published in the near future?

@ezekg
Copy link

ezekg commented Feb 10, 2022

@ondrejbartas let me know if you want to open up sponsors for the project?

Would be happy to sponsor to get new versions cut every once in awhile.

@ryanwilsonperkin
Copy link

https://github.com/ondrejbartas/sidekiq-cron/releases/tag/v1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redis#exists(key) Warning from redis 4.2.0