redic 1.0.0 → 1.0.1
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 +15 -16
- data/redic.gemspec +1 -1
- data/tests/redic_test.rb +41 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba65ff4580315a8788983af009026bff12e3634
|
4
|
+
data.tar.gz: 24bdd4a1198cdcce1b5b2a961037f1a0708ae803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 705de80d86e04f31637b4ea76496b69afff0e79e631d8fe5d312c2083d739abb88c1023760372d15d843b621b39d216c16c4e4b4edce88afc83e13f03a347527
|
7
|
+
data.tar.gz: 784f89f58b9bfec889c7f88884fa1ffed28bec17f1b30843f2cf1338dde46bafcf1e908df6c6346fb99aea80aadde5dc4e17e4c974252e0707e6b63da9b082ca
|
data/lib/redic/client.rb
CHANGED
@@ -39,30 +39,29 @@ class Redic
|
|
39
39
|
raise err, "Can't connect to: %s" % @uri
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def authenticate
|
47
|
-
if @uri.password
|
48
|
-
@semaphore.synchronize do
|
49
|
-
write ["AUTH", @uri.password]
|
50
|
-
read
|
51
|
-
end
|
42
|
+
if @uri.scheme == "redis"
|
43
|
+
@uri.password && assert_ok(call("AUTH", @uri.password))
|
44
|
+
@uri.path && assert_ok(call("SELECT", @uri.path[1..-1]))
|
52
45
|
end
|
53
46
|
end
|
54
47
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
read
|
60
|
-
end
|
48
|
+
def call(*args)
|
49
|
+
@semaphore.synchronize do
|
50
|
+
write(args)
|
51
|
+
read
|
61
52
|
end
|
62
53
|
end
|
63
54
|
|
64
55
|
def connected?
|
65
56
|
@connection && @connection.connected?
|
66
57
|
end
|
58
|
+
|
59
|
+
def assert(value, error)
|
60
|
+
raise error unless value
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_ok(reply)
|
64
|
+
assert(reply == "OK", reply)
|
65
|
+
end
|
67
66
|
end
|
68
67
|
end
|
data/redic.gemspec
CHANGED
data/tests/redic_test.rb
CHANGED
@@ -15,7 +15,48 @@ test "url" do |c|
|
|
15
15
|
assert_equal "redis://localhost:6379/", c.url
|
16
16
|
end
|
17
17
|
|
18
|
+
test "select db from url" do |c1|
|
19
|
+
|
20
|
+
# Connect to db 1
|
21
|
+
c2 = Redic.new("redis://localhost:6379/2")
|
22
|
+
|
23
|
+
c2.call("FLUSHDB")
|
24
|
+
|
25
|
+
# Set a value in db 0
|
26
|
+
c1.call("SET", "foo", "bar")
|
27
|
+
|
28
|
+
assert_equal(1, c1.call("DBSIZE"))
|
29
|
+
assert_equal(0, c2.call("DBSIZE"))
|
30
|
+
end
|
31
|
+
|
32
|
+
test "error when selecting db from url" do
|
33
|
+
c2 = Redic.new("redis://localhost:6379/foo")
|
34
|
+
|
35
|
+
assert_raise(RuntimeError) do
|
36
|
+
|
37
|
+
# Connection is lazy, send a command
|
38
|
+
c2.call("PING")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test "error when authenticating from url" do
|
43
|
+
|
44
|
+
# The correct password for 6380 is "foo"
|
45
|
+
c2 = Redic.new("redis://:foo@localhost:6380/")
|
46
|
+
c2.call("PING")
|
47
|
+
|
48
|
+
# The password provided is wrong
|
49
|
+
c3 = Redic.new("redis://:bar@localhost:6380/")
|
50
|
+
|
51
|
+
assert_raise(RuntimeError) do
|
52
|
+
|
53
|
+
# Connection is lazy, send a command
|
54
|
+
c3.call("PING")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
18
58
|
test "timeout" do |c1|
|
59
|
+
|
19
60
|
# Default timeout is 10 seconds
|
20
61
|
assert_equal 10_000_000, c1.timeout
|
21
62
|
|