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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9183d64596ee7f88393c7ef2a9469e493622dbd
4
- data.tar.gz: fbf9569e2e8d3ee9c55693decebc6a60b2aff295
3
+ metadata.gz: 2c5939511fb1a459b3a6674d0adccd6138235674
4
+ data.tar.gz: 25c640746707e9b6a34fc016110a8b5069ad730b
5
5
  SHA512:
6
- metadata.gz: 3a6fb3550295bdada1eb956aa8fc15ea46db14cf35ec19bcdbf0c5521bbfe6a9f0a87395ed000c1f5f53dec492feba389c703b0e46115af280184f096b778403
7
- data.tar.gz: e84272270e33d8ca0eee876df181666b37dea65b0c361ef3379aa748d857632f6257909509d20a205f2e01d4811d8ec624cc1c0dfe254c99584b37ebede604ba
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 client
301
- itself. This is useful for more advanced usage such as sharing an existing redis
302
- connection, utilizing [Redis::Namespace](https://github.com/resque/redis-namespace),
303
- or utilizing [hiredis](https://github.com/redis/hiredis-rb).
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
- client.set(key, (Time.now + ttl).to_i, ex: ttl, nx: true)
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
- client.set(key, (Time.now + ttl).to_i, ex: ttl)
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.del(key)
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
@@ -7,7 +7,7 @@ module Circuitry
7
7
  end
8
8
 
9
9
  def name
10
- arn.split(':').last
10
+ @name ||= arn.split(':').last
11
11
  end
12
12
 
13
13
  def ==(obj)
@@ -1,3 +1,3 @@
1
1
  module Circuitry
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
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.0
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-10-09 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-aws