redis-semaphore 0.2.3 → 0.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/redis/semaphore.rb +4 -3
- data/spec/semaphore_spec.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NThjZDI5NWY4MjY4Zjc2OWU3ODgxMTUwYjM1NDMyNjEyNjU0ZmY3YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTMzNTlhMjUxZjY3Mzg2ZDAzNWQwMjgxNGUxYzUzNDQ5NTFlMDA3YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTRiMjNkYTdlYWQ3OTkxY2MwYTI0NjIyNzcyM2U0NjQ3MTRhNWRhM2VmNDNk
|
10
|
+
MDJkZDUzODE5NWQ5ZjE4YWM0NmVhMzNjMDllOTZiMGFlNjA5YWJjNmMwNWVl
|
11
|
+
Yjk2NTVjN2IzYjUxN2QzZTA3MjBmYmZjMzk2YWFlODViZmYyNjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzdmYjMzMzlhMDZjZGZjNTVjZGUwNWRlMTk4N2EzYTlkZWFkMjU5ZWIzY2I1
|
14
|
+
ZGVlYjM1N2QwYzg3YTFiMDFkYzE3YzM0YTY2OGJmYTgzYTI3Njg0YjEzYmY2
|
15
|
+
YTQ5ZDQ2YjY3MWRjNjIzZmIyYmNlMDNkMDQ5OWM0MmNjNzhmNjQ=
|
data/lib/redis/semaphore.rb
CHANGED
@@ -54,16 +54,17 @@ class Redis
|
|
54
54
|
current_token = token_pair[1]
|
55
55
|
@tokens.push(current_token)
|
56
56
|
@redis.hset(grabbed_key, current_token, current_time.to_f)
|
57
|
-
|
57
|
+
return_value = current_token
|
58
|
+
|
58
59
|
if block_given?
|
59
60
|
begin
|
60
|
-
yield current_token
|
61
|
+
return_value = yield current_token
|
61
62
|
ensure
|
62
63
|
signal(current_token)
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
|
+
return_value
|
67
68
|
end
|
68
69
|
alias_method :wait, :lock
|
69
70
|
|
data/spec/semaphore_spec.rb
CHANGED
@@ -95,6 +95,23 @@ describe "redis" do
|
|
95
95
|
|
96
96
|
expect(semaphore.locked?).to eq(false)
|
97
97
|
end
|
98
|
+
|
99
|
+
it "should return the value of the block if block-style locking is used" do
|
100
|
+
block_value = semaphore.lock(1) do
|
101
|
+
42
|
102
|
+
end
|
103
|
+
expect(block_value).to eq(42)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "can return the passed in token to replicate old behaviour" do
|
107
|
+
lock_token = semaphore.lock(1)
|
108
|
+
semaphore.unlock()
|
109
|
+
|
110
|
+
block_value = semaphore.lock(1) do |token|
|
111
|
+
token
|
112
|
+
end
|
113
|
+
expect(block_value).to eq(lock_token)
|
114
|
+
end
|
98
115
|
end
|
99
116
|
|
100
117
|
describe "semaphore without staleness checking" do
|