redic 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/redic/client.rb +5 -24
- data/redic.gemspec +1 -1
- data/test/redic_test.rb +44 -2
- 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: 764359a897686829a6256da74c6cb9b09431c145
|
4
|
+
data.tar.gz: 326b89336c17823309e87f0892c674d1d3162649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b15177f76ea1af68c1dd3b18689310df67d2ab867034df7e0039607236c283c5dff4e29189d1bc43c8e7989ced9a9a1bd502611cd5cdc9b1c84ac61b86244e79
|
7
|
+
data.tar.gz: ebd8fbb06218eff075bed70ffa38ef0b8c48a444c7e41189ba097cadf9ee10f53ce3f7234b7a946f296ab9f79737959a541f06f64c77416fcfc324343984efdc
|
data/lib/redic/client.rb
CHANGED
@@ -10,9 +10,7 @@ class Redic
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def read
|
13
|
-
@connection.read
|
14
|
-
raise reply if reply.kind_of?(RuntimeError)
|
15
|
-
end
|
13
|
+
@connection.read
|
16
14
|
end
|
17
15
|
|
18
16
|
def write(command)
|
@@ -20,35 +18,18 @@ class Redic
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def connect
|
23
|
-
|
24
|
-
establish_connection unless connected?
|
25
|
-
|
26
|
-
@semaphore.synchronize do
|
27
|
-
yield
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
21
|
+
establish_connection unless connected?
|
31
22
|
|
32
|
-
|
33
|
-
def try(times)
|
34
|
-
tries = 0
|
35
|
-
|
36
|
-
begin
|
23
|
+
@semaphore.synchronize do
|
37
24
|
yield
|
38
|
-
rescue Exception => err
|
39
|
-
if (tries += 1) <= times
|
40
|
-
sleep 0.01
|
41
|
-
retry
|
42
|
-
else
|
43
|
-
raise err, "%s (retries=%d)" % [err.message, tries]
|
44
|
-
end
|
45
25
|
end
|
46
26
|
end
|
47
27
|
|
28
|
+
private
|
48
29
|
def establish_connection
|
49
30
|
begin
|
50
31
|
@connection = Redic::Connection.new(@uri)
|
51
|
-
rescue
|
32
|
+
rescue StandardError => err
|
52
33
|
raise err, "Can't connect to: %s" % @uri
|
53
34
|
end
|
54
35
|
|
data/redic.gemspec
CHANGED
data/test/redic_test.rb
CHANGED
@@ -30,7 +30,49 @@ test "multi/exec" do |c|
|
|
30
30
|
end
|
31
31
|
|
32
32
|
test "runtime errors" do |c|
|
33
|
-
|
34
|
-
|
33
|
+
res = c.call("KABLAMMO")
|
34
|
+
|
35
|
+
assert res.is_a?(RuntimeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
test "encoding" do |c|
|
39
|
+
Encoding.default_external = "UTF-8"
|
40
|
+
|
41
|
+
c.call("SET", "foo", "שלום")
|
42
|
+
|
43
|
+
assert_equal "Shalom שלום", "Shalom " + c.call("GET", "foo")
|
44
|
+
|
45
|
+
end if defined?(Encoding)
|
46
|
+
|
47
|
+
test "errors in pipeline" do |c|
|
48
|
+
c.write("SET", "foo", "bar")
|
49
|
+
c.write("INCR", "foo")
|
50
|
+
c.write("GET", "foo")
|
51
|
+
|
52
|
+
res = c.run
|
53
|
+
|
54
|
+
assert "OK" == res[0]
|
55
|
+
assert RuntimeError === res[1]
|
56
|
+
assert "bar" == res[2]
|
57
|
+
end
|
58
|
+
|
59
|
+
test "thread safety" do |c|
|
60
|
+
c.call("SET", "foo", 1)
|
61
|
+
c.call("SET", "bar", 2)
|
62
|
+
|
63
|
+
foos, bars = nil, nil
|
64
|
+
|
65
|
+
t1 = Thread.new do
|
66
|
+
foos = Array.new(100) { c.call("GET", "foo") }
|
35
67
|
end
|
68
|
+
|
69
|
+
t2 = Thread.new do
|
70
|
+
bars = Array.new(100) { c.call("GET", "bar") }
|
71
|
+
end
|
72
|
+
|
73
|
+
t1.join
|
74
|
+
t2.join
|
75
|
+
|
76
|
+
assert_equal ["1"], foos.uniq
|
77
|
+
assert_equal ["2"], bars.uniq
|
36
78
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hiredis
|