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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01a706218016d189d42e00bd2aecd14efae46f36
4
- data.tar.gz: 8b1633116cc4102fb194fe39bb80aee4a3c15f13
3
+ metadata.gz: e5948db3a01bfab1c1a21487b0068c50162a8b76
4
+ data.tar.gz: ebdb67ec3cd50b74c42b73a9793be3ea0aa284ce
5
5
  SHA512:
6
- metadata.gz: 3680dc68f7fb0fe088427164b49d33ce1ce1bed2b988a3ffdc49f28a91885bce7d8c504f325ee76b74c53d2e0448a1564388a62d8df80b405094b902a8350905
7
- data.tar.gz: 0dfbed587a00b0f46cb24683ce33743d81faef9047f1ce77f20b0c926d169adbba2aa407470dc6085e1d7302d7d4af2fce29c33d3cc2800b5c5f64b82a24bbce
6
+ metadata.gz: b0e7642262a046da4ac531bb36e4bc80be39a9c7f9ef436979f782474c11779bc9a80aac49ace7fd380e797dbd96ccdf560137a561dd7c8581eccc64cc7be6b9
7
+ data.tar.gz: 81bcd3bf002d1b5234113a4e732058440e4aaeaeb61e566ab4424a13545e8029b4b5f01f99fdef0c23951a2c84cf0e147e2207dd0cff2244b11ecaeb388f83a1
@@ -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
  }
@@ -1,3 +1,3 @@
1
1
  class Redlock
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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.3
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-20 00:00:00.000000000 Z
12
+ date: 2014-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler