circuitry 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/circuitry/locks/redis.rb +21 -3
- data/lib/circuitry/topic.rb +1 -1
- data/lib/circuitry/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: 2c5939511fb1a459b3a6674d0adccd6138235674
|
4
|
+
data.tar.gz: 25c640746707e9b6a34fc016110a8b5069ad730b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2119226fb89515758f04f426bf5b1d8e5576e27a7a1e12108ad35b8b0e03dc0085d42184095a2dd8a347d7c5a58cd3b6409edb55fa5d661bc29f8958ba8125e5
|
7
|
+
data.tar.gz: f1a5eadbfcf85445908d6c333eed171ac49e3e28d851a949460dd84f5282a67150ce244c8f3ea13c23f7ff708e479e2ee5966857cba827a4353b4fa8261c030f
|
data/README.md
CHANGED
@@ -297,14 +297,19 @@ a new `Redis` object.
|
|
297
297
|
Circuitry::Locks::Redis.new(url: 'redis://localhost:6379')
|
298
298
|
```
|
299
299
|
|
300
|
-
The second way is to pass in a `:client` option that specifies the redis
|
301
|
-
itself
|
302
|
-
|
303
|
-
|
300
|
+
The second way is to pass in a `:client` option that specifies either the redis
|
301
|
+
client itself or a [ConnectionPool](https://github.com/mperham/connection_pool)
|
302
|
+
of redis clients. This is useful for more advanced usage such as sharing an
|
303
|
+
existing redis connection, connection pooling, utilizing
|
304
|
+
[Redis::Namespace](https://github.com/resque/redis-namespace), or utilizing
|
305
|
+
[hiredis](https://github.com/redis/hiredis-rb).
|
304
306
|
|
305
307
|
```ruby
|
306
308
|
client = Redis.new(url: 'redis://localhost:6379')
|
307
309
|
Circuitry::Locks::Redis.new(client: client)
|
310
|
+
|
311
|
+
client = ConnectionPool.new(size: 5) { Redis.new }
|
312
|
+
Circuitry::Locks::Redis.new(client: client)
|
308
313
|
```
|
309
314
|
|
310
315
|
#### Memcache
|
@@ -15,20 +15,38 @@ module Circuitry
|
|
15
15
|
protected
|
16
16
|
|
17
17
|
def lock(key, ttl)
|
18
|
-
|
18
|
+
with_pool do |client|
|
19
|
+
client.set(key, (Time.now + ttl).to_i, ex: ttl, nx: true)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def lock!(key, ttl)
|
22
|
-
|
24
|
+
with_pool do |client|
|
25
|
+
client.set(key, (Time.now + ttl).to_i, ex: ttl)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def unlock!(key)
|
26
|
-
client
|
30
|
+
with_pool do |client|
|
31
|
+
client.del(key)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
private
|
30
36
|
|
31
37
|
attr_accessor :client
|
38
|
+
|
39
|
+
def with_pool(&block)
|
40
|
+
if pool?
|
41
|
+
client.with(&block)
|
42
|
+
else
|
43
|
+
block.call(client)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def pool?
|
48
|
+
defined?(ConnectionPool) && client.is_a?(ConnectionPool)
|
49
|
+
end
|
32
50
|
end
|
33
51
|
end
|
34
52
|
end
|
data/lib/circuitry/topic.rb
CHANGED
data/lib/circuitry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuitry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Huggins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-aws
|