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

Use hscan for Util#expire #229

Merged
merged 3 commits into from
Jun 17, 2017
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
8 changes: 7 additions & 1 deletion lib/sidekiq_unique_jobs/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Util
DEFAULT_COUNT ||= 1_000
KEYS_METHOD ||= 'keys'
SCAN_METHOD ||= 'scan'
EXPIRE_BATCH_SIZE ||= 100

module_function

Expand Down Expand Up @@ -43,11 +44,16 @@ def unique_hash
def expire
removed_keys = {}
connection do |conn|
conn.hgetall(SidekiqUniqueJobs::HASH_KEY).each do |jid, unique_key|
cursor = '0'
cursor, jobs = conn.hscan(SidekiqUniqueJobs::HASH_KEY, [cursor, 'MATCH', '*', 'COUNT', EXPIRE_BATCH_SIZE])
jobs.each do |job_array|
jid, unique_key = job_array
next if conn.get(unique_key)
conn.hdel(SidekiqUniqueJobs::HASH_KEY, jid)
removed_keys[jid] = unique_key
end

break if cursor == '0'
end
removed_keys
end
Expand Down