From 9de48c0eb91893fe19f3c9179a5f0e8c3c9c61d7 Mon Sep 17 00:00:00 2001 From: Tobias Svensson Date: Mon, 16 Sep 2013 17:29:47 +0100 Subject: [PATCH] Add Lock::Redis#unlock!. --- lib/sidetiq/lock/redis.rb | 6 ++++++ test/test_lock.rb | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/sidetiq/lock/redis.rb b/lib/sidetiq/lock/redis.rb index cb385c7..22af2b1 100644 --- a/lib/sidetiq/lock/redis.rb +++ b/lib/sidetiq/lock/redis.rb @@ -74,6 +74,12 @@ module Sidetiq end end + def unlock! + Sidekiq.redis do |redis| + redis.del(key) + end + end + private def extract_key(key) diff --git a/test/test_lock.rb b/test/test_lock.rb index 862c3f9..96440b9 100644 --- a/test/test_lock.rb +++ b/test/test_lock.rb @@ -31,6 +31,16 @@ class TestLock < Sidetiq::TestCase assert_equal "sidetiq:Foobar:lock", locks.first.key end + def test_unlock! + Sidekiq.redis do |redis| + redis.set("sidetiq:Foobar:lock", 1) + + Sidetiq::Lock::Redis.new("Foobar").unlock! + + assert_nil redis.get("sidetiq:Foobar:lock") + end + end + def test_lock_sets_correct_meta_data key = SecureRandom.hex(8) internal_key = "sidetiq:#{key}:lock"