redic 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/redic/client.rb +11 -1
  3. data/redic.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c3cb18b1fbaf7287872bb80f00dcf56ea80c876
4
- data.tar.gz: f73a0f93ee0b747238614d6eefca1272b1df6e94
3
+ metadata.gz: 76317fcd4c61e79f065cf2ef44837f3a051d03aa
4
+ data.tar.gz: 30ac403657f5104e8a36dcaf62ec94ee44cc8885
5
5
  SHA512:
6
- metadata.gz: 5e1b59a35e39d75d09443205e334d55d18c00093de1902a807eb85989dd17ca898c8e6e6964dc25d688c522503739dc250ad5ff1a3c8a706d2df784dbf236cb7
7
- data.tar.gz: c0f0d5cc628053da0b59b434168141a3789b642a6098ddc88dd067acfa35662f824a4f7001538141eea69c750a1679f2ff31df0c0099c53fa21e57f4202eb091
6
+ metadata.gz: a7e7595fc878f1788903bbbbe3f9303138c761172ffc73d62c2839a3cd9ad339c32e87dffff8465a9e574884eaf2114a673a87d85821b4b49e5fe416e59569b5
7
+ data.tar.gz: 80c811c3edc5114dd07c8ac4d43d5851809576774dc5f0c12846b3592754f4ad4a2f7cad9cb8fe1a8c089d55589ad2982240e31628359e5142c3ee5b8ba21cf5
@@ -5,6 +5,7 @@ class Redic
5
5
  class Client
6
6
  def initialize(url)
7
7
  @uri = URI.parse(url)
8
+ @ttl = Integer(ENV.fetch("REDIC_TTL", 60))
8
9
  @connection = nil
9
10
  @semaphore = Mutex.new
10
11
  end
@@ -19,6 +20,7 @@ class Redic
19
20
 
20
21
  def connect
21
22
  establish_connection unless connected?
23
+ timestamp_connection
22
24
 
23
25
  @semaphore.synchronize do
24
26
  yield
@@ -36,6 +38,10 @@ class Redic
36
38
  authenticate
37
39
  end
38
40
 
41
+ def timestamp_connection
42
+ @timestamp = Time.now.to_i
43
+ end
44
+
39
45
  def authenticate
40
46
  if @uri.password
41
47
  @semaphore.synchronize do
@@ -46,7 +52,11 @@ class Redic
46
52
  end
47
53
 
48
54
  def connected?
49
- @connection && @connection.connected?
55
+ @connection && @connection.connected? && alive?
56
+ end
57
+
58
+ def alive?
59
+ Time.now.to_i - @timestamp < @ttl
50
60
  end
51
61
  end
52
62
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "redic"
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
6
6
  s.summary = "Lightweight Redis Client"
7
7
  s.description = "Lightweight Redis Client"
8
8
  s.authors = ["Michel Martens", "Cyril David"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-29 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis