redic 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +1 -1
- data/lib/redic.rb +4 -0
- data/lib/redic/client.rb +27 -6
- data/redic.gemspec +1 -1
- data/tests/redic_test.rb +36 -10
- 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: a910a65a110dbb59ba57ac6f9bc012b12b59a1ff
|
4
|
+
data.tar.gz: 0b0af9cbf96cb99db9d854b1cc491df57afacffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44bf2375dedfd7694997dafcf6b6c2202fded203ff330100af7141cf8581680be1381060b9c7e22af90047c9036ebae4a4f1a24cca63fa05728dbefc495d8360
|
7
|
+
data.tar.gz: 83967139fd09cbce0f1c706b3b4535e376cf880489c362f3252c3e1970303e4413b1a156ca2318b20bc33ab94b578f7a6846116402a9489e0c8db6c7ac3a96af
|
data/.gems
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
cutest -v 1.2.0
|
2
|
-
hiredis -v 0.
|
2
|
+
hiredis -v 0.6.0
|
data/lib/redic.rb
CHANGED
data/lib/redic/client.rb
CHANGED
@@ -7,13 +7,16 @@ class Redic
|
|
7
7
|
|
8
8
|
def initialize(url, timeout)
|
9
9
|
@semaphore = Mutex.new
|
10
|
+
@connection = false
|
11
|
+
|
10
12
|
configure(url, timeout)
|
11
13
|
end
|
12
14
|
|
13
15
|
def configure(url, timeout)
|
16
|
+
disconnect!
|
17
|
+
|
14
18
|
@uri = URI.parse(url)
|
15
19
|
@timeout = timeout
|
16
|
-
@connection = nil
|
17
20
|
end
|
18
21
|
|
19
22
|
def read
|
@@ -31,10 +34,32 @@ class Redic
|
|
31
34
|
yield
|
32
35
|
end
|
33
36
|
rescue Errno::ECONNRESET
|
34
|
-
@connection =
|
37
|
+
@connection = false
|
35
38
|
retry
|
36
39
|
end
|
37
40
|
|
41
|
+
def connected?
|
42
|
+
@connection && @connection.connected?
|
43
|
+
end
|
44
|
+
|
45
|
+
def disconnect!
|
46
|
+
if connected?
|
47
|
+
@connection.disconnect
|
48
|
+
@connection = false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def quit
|
53
|
+
if connected?
|
54
|
+
assert_ok(call("QUIT"))
|
55
|
+
disconnect!
|
56
|
+
|
57
|
+
true
|
58
|
+
else
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
38
63
|
private
|
39
64
|
def establish_connection
|
40
65
|
begin
|
@@ -56,10 +81,6 @@ class Redic
|
|
56
81
|
end
|
57
82
|
end
|
58
83
|
|
59
|
-
def connected?
|
60
|
-
@connection && @connection.connected?
|
61
|
-
end
|
62
|
-
|
63
84
|
def assert(value, error)
|
64
85
|
raise error unless value
|
65
86
|
end
|
data/redic.gemspec
CHANGED
data/tests/redic_test.rb
CHANGED
@@ -4,7 +4,14 @@ require_relative "../lib/redic"
|
|
4
4
|
REDIS_URL = "redis://localhost:6379/"
|
5
5
|
|
6
6
|
prepare do
|
7
|
-
Redic.new(REDIS_URL)
|
7
|
+
c = Redic.new(REDIS_URL)
|
8
|
+
begin
|
9
|
+
c.call("FLUSHDB")
|
10
|
+
rescue
|
11
|
+
c.call("AUTH", "foo")
|
12
|
+
c.call("FLUSHDB")
|
13
|
+
c.call("CONFIG", "SET", "requirepass", "")
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
setup do
|
@@ -39,20 +46,25 @@ test "error when selecting db from url" do
|
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
|
-
test "error when authenticating from url" do
|
49
|
+
test "error when authenticating from url" do |c1|
|
43
50
|
|
44
|
-
#
|
45
|
-
|
46
|
-
c2.call("PING")
|
51
|
+
# Configure password as "foo"
|
52
|
+
c1.call("CONFIG", "SET", "requirepass", "foo")
|
47
53
|
|
48
54
|
# The password provided is wrong
|
49
|
-
|
55
|
+
c2 = Redic.new("redis://:bar@localhost:6379/")
|
50
56
|
|
51
57
|
assert_raise(RuntimeError) do
|
52
58
|
|
53
59
|
# Connection is lazy, send a command
|
54
|
-
|
60
|
+
c2.call("PING")
|
55
61
|
end
|
62
|
+
|
63
|
+
c3 = Redic.new("redis://:foo@localhost:6379/")
|
64
|
+
assert_equal "PONG", c3.call("PING")
|
65
|
+
|
66
|
+
# Remove password
|
67
|
+
c3.call("CONFIG", "SET", "requirepass", "")
|
56
68
|
end
|
57
69
|
|
58
70
|
test "Can connect to sentinel" do
|
@@ -175,9 +187,23 @@ test "pub/sub" do |c1|
|
|
175
187
|
end
|
176
188
|
|
177
189
|
test "reconnect" do |c1|
|
178
|
-
|
190
|
+
c1.call("CONFIG", "SET", "requirepass", "foo")
|
191
|
+
|
192
|
+
c1.configure("redis://:foo@localhost:6379/")
|
193
|
+
|
194
|
+
assert_equal "PONG", c1.call("PING")
|
195
|
+
end
|
196
|
+
|
197
|
+
test "disconnect" do |c1|
|
198
|
+
|
199
|
+
# Connection is lazy
|
200
|
+
assert_equal false, c1.client.connected?
|
201
|
+
assert_equal false, c1.quit
|
202
|
+
|
203
|
+
c1.call("PING")
|
179
204
|
|
180
|
-
c1.
|
205
|
+
assert_equal true, c1.client.connected?
|
206
|
+
assert_equal true, c1.quit
|
181
207
|
|
182
|
-
assert_equal
|
208
|
+
assert_equal false, c1.client.connected?
|
183
209
|
end
|
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: 1.
|
4
|
+
version: 1.4.0
|
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: 2015-
|
12
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiredis
|