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 +13 -5
- data/README.md +4 -0
- data/lib/redlock/client.rb +2 -6
- data/lib/redlock/version.rb +1 -1
- data/spec/client_spec.rb +4 -3
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2ZjYTlmOTc2ZTc0MmYxZGE0MzBiNzY2ZjEzOGMxOWU4YjE3NzRhMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjMwOGMxNTRkMDliODFmYjI3YWY5MWQ3ZTdjMjUzMDNlNTdiNDQ4Yg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
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
|
|
data/lib/redlock/client.rb
CHANGED
@@ -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.
|
80
|
+
@redis.set(resource, val, nx: true, px: ttl)
|
85
81
|
end
|
86
82
|
|
87
83
|
def unlock(resource, val)
|
88
|
-
redis.
|
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
|
data/lib/redlock/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -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.
|
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.
|
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-
|
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: []
|