Skip to content

Commit

Permalink
Merge pull request #1 from MikeRogers0/bug/fix-redis-warning
Browse files Browse the repository at this point in the history
fix: Redis exists? deprecation warning
  • Loading branch information
cbaudouinjr authored Jan 27, 2021
2 parents 7ca90f9 + 9957edc commit 571d7d7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/sidekiq/cron/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Job
REMEMBER_THRESHOLD = 24 * 60 * 60
LAST_ENQUEUE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'

# Use the exists? method if we're on a newer version of redis.
REDIS_EXISTS_METHOD = Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?

#crucial part of whole enquing job
def should_enque? time
enqueue = false
Expand Down Expand Up @@ -461,7 +464,7 @@ def save

#add information about last time! - don't enque right after scheduler poller starts!
time = Time.now.utc
conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.exists(job_enqueued_key)
conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.public_send(REDIS_EXISTS_METHOD, job_enqueued_key)
end
logger.info { "Cron Jobs - add job with name: #{@name}" }
end
Expand Down Expand Up @@ -540,7 +543,7 @@ def formated_last_time now = Time.now.utc
def self.exists? name
out = false
Sidekiq.redis do |conn|
out = conn.exists redis_key name
out = conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
end
out
end
Expand Down

0 comments on commit 571d7d7

Please sign in to comment.