suo 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/lib/suo/client/base.rb +6 -2
- data/lib/suo/client/memcached.rb +1 -1
- data/lib/suo/client/redis.rb +4 -2
- data/lib/suo/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: ad72e1c0045977e0ccffb7a56d1d652f3ca12fc8
|
4
|
+
data.tar.gz: b715298aacc8f3f7773103d0f7a7086ece89ef32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebc31f887ba239304901a342b33c0ec8a6065204b46eb923087524e2d23579dfce42f73ee7220f317ffa9b032e474c08f085b1693023148c2cc9b20c8569d4c9
|
7
|
+
data.tar.gz: 9acbeeac7c2dca1ffec0807ebd8aaf56fa1b53f7c7f300f45fd52b0e68e8638506d1622c6b506cf0455a22ed8aafa177b975961e5fb623387be5bfe6fccff531
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ end
|
|
34
34
|
# The resources argument is the number of resources the semaphore will allow to lock (defaulting to one - a mutex)
|
35
35
|
suo = Suo::Client::Memcached.new("bar_resource", client: some_dalli_client, resources: 2)
|
36
36
|
|
37
|
-
Thread.new { suo.lock{ puts "One"; sleep 2 } }
|
37
|
+
Thread.new { suo.lock { puts "One"; sleep 2 } }
|
38
38
|
Thread.new { suo.lock { puts "Two"; sleep 2 } }
|
39
39
|
Thread.new { suo.lock { puts "Three" } }
|
40
40
|
|
@@ -46,7 +46,7 @@ suo = Suo::Client::Memcached.new("protected_key", client: some_dalli_client, acq
|
|
46
46
|
# manually locking/unlocking
|
47
47
|
# the return value from lock without a block is a unique token valid only for the current lock
|
48
48
|
# which must be unlocked manually
|
49
|
-
token = suo
|
49
|
+
token = suo.lock
|
50
50
|
foo.baz!
|
51
51
|
suo.unlock(token)
|
52
52
|
|
@@ -77,7 +77,7 @@ end
|
|
77
77
|
|
78
78
|
## History
|
79
79
|
|
80
|
-
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md)
|
80
|
+
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md).
|
81
81
|
|
82
82
|
## Contributing
|
83
83
|
|
data/lib/suo/client/base.rb
CHANGED
@@ -8,17 +8,21 @@ module Suo
|
|
8
8
|
resources: 1
|
9
9
|
}.freeze
|
10
10
|
|
11
|
+
BLANK_STR = "".freeze
|
12
|
+
|
11
13
|
attr_accessor :client, :key, :resources, :options
|
12
14
|
|
13
15
|
include MonitorMixin
|
14
16
|
|
15
17
|
def initialize(key, options = {})
|
16
18
|
fail "Client required" unless options[:client]
|
19
|
+
|
17
20
|
@options = DEFAULT_OPTIONS.merge(options)
|
18
21
|
@retry_count = (@options[:acquisition_timeout] / @options[:acquisition_delay].to_f).ceil
|
19
22
|
@client = @options[:client]
|
20
23
|
@resources = @options[:resources].to_i
|
21
24
|
@key = key
|
25
|
+
|
22
26
|
super() # initialize Monitor mixin for thread safety
|
23
27
|
end
|
24
28
|
|
@@ -124,7 +128,7 @@ module Suo
|
|
124
128
|
fail NotImplementedError
|
125
129
|
end
|
126
130
|
|
127
|
-
def initial_set(val =
|
131
|
+
def initial_set(val = BLANK_STR) # rubocop:disable Lint/UnusedMethodArgument
|
128
132
|
fail NotImplementedError
|
129
133
|
end
|
130
134
|
|
@@ -158,7 +162,7 @@ module Suo
|
|
158
162
|
end
|
159
163
|
|
160
164
|
def deserialize_locks(val)
|
161
|
-
unpacked = (val.nil? || val ==
|
165
|
+
unpacked = (val.nil? || val == BLANK_STR) ? [] : MessagePack.unpack(val)
|
162
166
|
|
163
167
|
unpacked.map do |time, token|
|
164
168
|
[Time.at(time), token]
|
data/lib/suo/client/memcached.rb
CHANGED
data/lib/suo/client/redis.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Suo
|
2
2
|
module Client
|
3
3
|
class Redis < Base
|
4
|
+
OK_STR = "OK".freeze
|
5
|
+
|
4
6
|
def initialize(key, options = {})
|
5
7
|
options[:client] ||= ::Redis.new(options[:connection] || {})
|
6
8
|
super
|
@@ -21,7 +23,7 @@ module Suo
|
|
21
23
|
multi.set(@key, newval)
|
22
24
|
end
|
23
25
|
|
24
|
-
ret && ret[0] ==
|
26
|
+
ret && ret[0] == OK_STR
|
25
27
|
end
|
26
28
|
|
27
29
|
def synchronize
|
@@ -32,7 +34,7 @@ module Suo
|
|
32
34
|
@client.unwatch
|
33
35
|
end
|
34
36
|
|
35
|
-
def initial_set(val =
|
37
|
+
def initial_set(val = BLANK_STR)
|
36
38
|
@client.set(@key, val)
|
37
39
|
end
|
38
40
|
end
|
data/lib/suo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Elser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dalli
|