diff --git a/lib/sidekiq_unique_jobs/lua/unlock.lua b/lib/sidekiq_unique_jobs/lua/unlock.lua index 15ebfea3..3cace144 100644 --- a/lib/sidekiq_unique_jobs/lua/unlock.lua +++ b/lib/sidekiq_unique_jobs/lua/unlock.lua @@ -85,6 +85,11 @@ if locked_count and locked_count < 1 then redis.call(del_cmd, locked) end +if redis.call("LLEN", primed) == 0 then + log_debug(del_cmd, primed) + redis.call(del_cmd, primed) +end + if limit and limit <= 1 and locked_count and locked_count <= 1 then log_debug("ZREM", digests, digest) redis.call("ZREM", digests, digest) diff --git a/spec/sidekiq_unique_jobs/lua/unlock_spec.rb b/spec/sidekiq_unique_jobs/lua/unlock_spec.rb index a47d13fc..86ffacf0 100644 --- a/spec/sidekiq_unique_jobs/lua/unlock_spec.rb +++ b/spec/sidekiq_unique_jobs/lua/unlock_spec.rb @@ -35,26 +35,36 @@ end shared_examples "unlock with ttl" do - it { expect { unlock }.to change { zcard(key.changelog) }.by(1) } - it { expect { unlock }.to change { ttl(key.digest) }.to(-2) } + it { expect { unlock }.to change { unique_keys }.to(%w[uniquejobs:digest:QUEUED]) } it { expect { unlock }.to change { llen(key.queued) }.by(1) } + it { expect { unlock }.to change { llen(key.primed) }.by(0) } + it { expect { unlock }.to change { ttl(key.locked) }.to(-2) } it { expect { unlock }.to change { hget(key.locked, job_id_one) }.to(nil) } + + it { expect { unlock }.to change { ttl(key.digest) }.to(-2) } it { expect { unlock }.to change { zcard(key.digests) }.by(-1) } it { expect { unlock }.to change { digests.entries }.from(key.digest => kind_of(Float)).to({}) } + + it { expect { unlock }.to change { zcard(key.changelog) }.by(1) } end shared_examples "unlock without ttl" do - it { expect { unlock }.to change { zcard(key.changelog) }.by(1) } - it { expect { unlock }.to change { ttl(key.digest) }.from(-1).to(-2) } + it { expect { unlock }.to change { unique_keys }.to(%w[uniquejobs:digest:QUEUED]) } it { expect { unlock }.to change { lrange(key.queued, -1, 0) }.to(["1"]) } it { expect { unlock }.to change { llen(key.queued) }.by(1) } + it { expect { unlock }.to change { llen(key.primed) }.by(0) } + it { expect { unlock }.to change { ttl(key.locked) }.to(-2) } it { expect { unlock }.to change { hget(key.locked, job_id_one) }.to(nil) } + + it { expect { unlock }.to change { ttl(key.digest) }.from(-1).to(-2) } it { expect { unlock }.to change { zcard(key.digests) }.by(-1) } it { expect { unlock }.to change { digests.entries }.from(key.digest => kind_of(Float)).to({}) } + + it { expect { unlock }.to change { zcard(key.changelog) }.by(1) } end context "with lock: :until_expired", :with_a_lock do