Skip to content

Commit

Permalink
use non-deprecated form of sadd/srem
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingreid authored and PatrickTulskie committed May 25, 2023
1 parent 121e342 commit cb67a44
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Resque Scheduler authors
- Henrik Nyh
- Hormoz Kheradmand
- Ian Davies
- Irving Reid
- James Le Cuirot
- Jarkko Mönkkönen
- Jimmy Chao
Expand Down Expand Up @@ -87,4 +88,4 @@ Resque Scheduler authors
- malomalo
- sawanoboly
- serek
- iloveitaly
- iloveitaly
2 changes: 1 addition & 1 deletion bin/migrate_to_timestamps_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
redis = Resque.redis
Array(redis.keys('delayed:*')).each do |key|
jobs = redis.lrange(key, 0, -1)
jobs.each { |job| redis.sadd("timestamps:#{job}", key) }
jobs.each { |job| redis.sadd("timestamps:#{job}", [key]) }
end
8 changes: 4 additions & 4 deletions lib/resque/scheduler/delaying_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def delayed_push(timestamp, item)
redis.rpush("delayed:#{timestamp.to_i}", encode(item))

# Store the timestamps at with this item occurs
redis.sadd("timestamps:#{encode(item)}", "delayed:#{timestamp.to_i}")
redis.sadd("timestamps:#{encode(item)}", ["delayed:#{timestamp.to_i}"])

# Now, add this timestamp to the zsets. The score and the value are
# the same since we'll be querying by timestamp, and we don't have
Expand Down Expand Up @@ -140,7 +140,7 @@ def next_item_for_timestamp(timestamp)
key = "delayed:#{timestamp.to_i}"

encoded_item = redis.lpop(key)
redis.srem("timestamps:#{encoded_item}", key)
redis.srem("timestamps:#{encoded_item}", [key])
item = decode(encoded_item)

# If the list is empty, remove it.
Expand Down Expand Up @@ -257,7 +257,7 @@ def remove_delayed_job_from_timestamp(timestamp, klass, *args)
key = "delayed:#{timestamp.to_i}"
encoded_job = encode(job_to_hash(klass, args))

redis.srem("timestamps:#{encoded_job}", key)
redis.srem("timestamps:#{encoded_job}", [key])
count = redis.lrem(key, 0, encoded_job)
clean_up_timestamp(key, timestamp)

Expand Down Expand Up @@ -333,7 +333,7 @@ def remove_delayed_job(encoded_job)
replies = redis.pipelined do |pipeline|
timestamps.each do |key|
pipeline.lrem(key, 0, encoded_job)
pipeline.srem("timestamps:#{encoded_job}", key)
pipeline.srem("timestamps:#{encoded_job}", [key])
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/resque/scheduler/scheduling_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_schedule(name, config, reload = true)
non_persistent_schedules[name] = decode(encode(config))
end

redis.sadd(:schedules_changed, name)
redis.sadd(:schedules_changed, [name])
reload_schedule! if reload
end

Expand All @@ -105,7 +105,7 @@ def fetch_schedule(name)
def remove_schedule(name, reload = true)
non_persistent_schedules.delete(name)
redis.hdel(:persistent_schedules, name)
redis.sadd(:schedules_changed, name)
redis.sadd(:schedules_changed, [name])

reload_schedule! if reload
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
require 'resque-scheduler'
require 'resque/scheduler/server'

# Raise on Redis deprecations if we're using a modern enough version of the Resque gem
if Redis.respond_to?(:'raise_deprecations=')
Redis.raise_deprecations = Gem.loaded_specs['resque'].version >= Gem::Version.create('2.4')
end

##
# test/spec/mini 3
# original work: http://gist.github.com/25455
Expand Down

0 comments on commit cb67a44

Please sign in to comment.