redic 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redic/client.rb +11 -1
- data/redic.gemspec +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: 76317fcd4c61e79f065cf2ef44837f3a051d03aa
|
4
|
+
data.tar.gz: 30ac403657f5104e8a36dcaf62ec94ee44cc8885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7e7595fc878f1788903bbbbe3f9303138c761172ffc73d62c2839a3cd9ad339c32e87dffff8465a9e574884eaf2114a673a87d85821b4b49e5fe416e59569b5
|
7
|
+
data.tar.gz: 80c811c3edc5114dd07c8ac4d43d5851809576774dc5f0c12846b3592754f4ad4a2f7cad9cb8fe1a8c089d55589ad2982240e31628359e5142c3ee5b8ba21cf5
|
data/lib/redic/client.rb
CHANGED
@@ -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
|
data/redic.gemspec
CHANGED
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.
|
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-
|
12
|
+
date: 2013-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiredis
|