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 deprecated uses of Redis#pipelined #740

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/resque/scheduler/delaying_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ def reset_delayed_queue
Array(redis.zrange(:delayed_queue_schedule, 0, -1)).each do |item|
key = "delayed:#{item}"
items = redis.lrange(key, 0, -1)
redis.pipelined do
items.each { |ts_item| redis.del("timestamps:#{ts_item}") }
end
redis.del key
redis.del(key, items.map { |ts_item| "timestamps:#{ts_item}" })
end

redis.del :delayed_queue_schedule
Expand Down Expand Up @@ -217,9 +214,9 @@ def find_delayed_selection(klass = nil, &block)

# Beyond 100 there's almost no improvement in speed
found = timestamps.each_slice(100).map do |ts_group|
jobs = redis.pipelined do |r|
jobs = redis.pipelined do |pipeline|
ts_group.each do |ts|
r.lrange("delayed:#{ts}", 0, -1)
pipeline.lrange("delayed:#{ts}", 0, -1)
end
end

Expand Down Expand Up @@ -299,10 +296,10 @@ def remove_delayed_job(encoded_job)

timestamps = redis.smembers("timestamps:#{encoded_job}")

replies = redis.pipelined do
replies = redis.pipelined do |pipeline|
timestamps.each do |key|
redis.lrem(key, 0, encoded_job)
redis.srem("timestamps:#{encoded_job}", key)
pipeline.lrem(key, 0, encoded_job)
pipeline.srem("timestamps:#{encoded_job}", key)
end
end

Expand All @@ -319,9 +316,9 @@ def clean_up_timestamp(key, timestamp)
redis.watch(key) do
if redis.llen(key).to_i == 0
# If the list is empty, remove it.
redis.multi do
redis.del(key)
redis.zrem(:delayed_queue_schedule, timestamp.to_i)
redis.multi do |transaction|
transaction.del(key)
transaction.zrem(:delayed_queue_schedule, timestamp.to_i)
end
else
redis.redis.unwatch
Expand Down