redlock 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e8e7d408cb9639c785875cbc975cd1fbb7166737
4
- data.tar.gz: 4f067eef13f678f00b85d55edab568471e37b23e
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2ZjYTlmOTc2ZTc0MmYxZGE0MzBiNzY2ZjEzOGMxOWU4YjE3NzRhMQ==
5
+ data.tar.gz: !binary |-
6
+ NjMwOGMxNTRkMDliODFmYjI3YWY5MWQ3ZTdjMjUzMDNlNTdiNDQ4Yg==
5
7
  SHA512:
6
- metadata.gz: 96f84d612fdd0ee0eb68b3d357d58e4f042077f10b5988d65fb95e01e2bb4b2f2758fb81671a002c29c76a361956e7207d36455ced2e37d25c0d14bbdf78501f
7
- data.tar.gz: 7283eac7e5222740298f5cb0b9849397fdaeb196ed2f2a218311cd127544da93a2ac7fe7063d010500762c224a4d811ff88e7c48e05b859c697665d305af9ead
8
+ metadata.gz: !binary |-
9
+ ZTg2ZTI4MzY0ZmI3MzhkYzlhNTA3NzVjMGYyZmJlNGVhNjAzODE0ZGY4M2Qz
10
+ NDI2ODJmYzU5MGI2YjM3MmMxNGQwNTRlYzM4ZTE0MWNhNmQyYWVlNGUyYmU4
11
+ YWM0OTUyMzQwNzdlNTk2ZTNiNGE4OTdjYTQzYmYwMjBjYjU5YmE=
12
+ data.tar.gz: !binary |-
13
+ N2Q1ZTcwZWRlNDYyZjY0MzY4MDA4ZTVhMjEwNTE3N2Q4MWZmOTY0MDA0MmIx
14
+ MjVlYzM3ZWQ1Y2RkODJiOTI0ZTZiYWQ3MjdmZWU2NWZkNzMyMGM2YzM2OTUy
15
+ NWJmMjNmNjU0YzgyNDNkNGVhMDM2OWJjZmMzY2NhMWY4MzVjZjI=
data/README.md CHANGED
@@ -84,6 +84,10 @@ end
84
84
  Make sure you have at least 1 redis instances up.
85
85
 
86
86
  $ rspec
87
+
88
+ ## Disclaimer
89
+
90
+ This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in your production environments. You can see discussion about this approach at [reddit](http://www.reddit.com/r/programming/comments/2nt0nq/distributed_lock_using_redis_implemented_in_ruby/).
87
91
 
88
92
  ## Contributing
89
93
 
@@ -76,16 +76,12 @@ module Redlock
76
76
  end
77
77
  end
78
78
 
79
- def redis
80
- @redis
81
- end
82
-
83
79
  def lock(resource, val, ttl)
84
- redis.client.call([:set, resource, val, 'NX', 'PX', ttl])
80
+ @redis.set(resource, val, nx: true, px: ttl)
85
81
  end
86
82
 
87
83
  def unlock(resource, val)
88
- redis.client.call([:eval, UNLOCK_SCRIPT, 1, resource, val])
84
+ @redis.eval(UNLOCK_SCRIPT, [resource], [val])
89
85
  rescue
90
86
  # Nothing to do, unlocking is just a best-effort attempt.
91
87
  end
@@ -1,3 +1,3 @@
1
1
  module Redlock
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -12,10 +12,11 @@ RSpec.describe Redlock::Client do
12
12
  servers = [ 'redis://localhost:6379', Redis.new(url: 'redis://someotherhost:6379') ]
13
13
  redlock = Redlock::Client.new(servers)
14
14
 
15
- redlock_servers = redlock.instance_variable_get(:@servers)
15
+ redlock_servers = redlock.instance_variable_get(:@servers).map do |s|
16
+ s.instance_variable_get(:@redis).client.host
17
+ end
16
18
 
17
- expect(redlock_servers.one? { |s| s.redis.client.host == 'localhost' })
18
- expect(redlock_servers.one? { |s| s.redis.client.port == 'someotherhost' })
19
+ expect(redlock_servers).to match_array(%w{ localhost someotherhost })
19
20
  end
20
21
  end
21
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Moreira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-18 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3'
20
- - - '>='
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 3.0.5
23
23
  type: :runtime
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3'
30
- - - '>='
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.0.5
33
33
  - !ruby/object:Gem::Dependency
@@ -48,14 +48,14 @@ dependencies:
48
48
  name: coveralls
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ! '>='
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
@@ -118,12 +118,12 @@ require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ! '>='
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - '>='
126
+ - - ! '>='
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []