ace_redlock 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redlock.rb +17 -0
- data/lib/redlock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5948db3a01bfab1c1a21487b0068c50162a8b76
|
4
|
+
data.tar.gz: ebdb67ec3cd50b74c42b73a9793be3ea0aa284ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e7642262a046da4ac531bb36e4bc80be39a9c7f9ef436979f782474c11779bc9a80aac49ace7fd380e797dbd96ccdf560137a561dd7c8581eccc64cc7be6b9
|
7
|
+
data.tar.gz: 81bcd3bf002d1b5234113a4e732058440e4aaeaeb61e566ab4424a13545e8029b4b5f01f99fdef0c23951a2c84cf0e147e2207dd0cff2244b11ecaeb388f83a1
|
data/lib/redlock.rb
CHANGED
@@ -34,6 +34,10 @@ class Redlock
|
|
34
34
|
@retry_delay = delay
|
35
35
|
end
|
36
36
|
|
37
|
+
def testing=(mode)
|
38
|
+
@testing_mode = mode
|
39
|
+
end
|
40
|
+
|
37
41
|
def lock_instance(redis,resource,val,ttl)
|
38
42
|
begin
|
39
43
|
return redis.set(resource, val, nx: true, px: ttl)
|
@@ -61,6 +65,17 @@ class Redlock
|
|
61
65
|
|
62
66
|
def lock(resource,ttl,val=nil)
|
63
67
|
val = get_unique_lock_id if val.nil?
|
68
|
+
|
69
|
+
if @testing_mode == :bypass
|
70
|
+
return {
|
71
|
+
validity: ttl,
|
72
|
+
resource: resource,
|
73
|
+
val: val
|
74
|
+
}
|
75
|
+
elsif @testing_mode == :fail
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
|
64
79
|
@retry_count.times {
|
65
80
|
n = 0
|
66
81
|
start_time = (Time.now.to_f*1000).to_i
|
@@ -90,6 +105,8 @@ class Redlock
|
|
90
105
|
end
|
91
106
|
|
92
107
|
def unlock(lock)
|
108
|
+
return if @testing_mode == :bypass
|
109
|
+
|
93
110
|
@servers.each{|s|
|
94
111
|
unlock_instance(s,lock[:resource],lock[:val])
|
95
112
|
}
|
data/lib/redlock/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ace_redlock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salvatore Sanfilippo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|