redic 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 826a4619b6aec694f3b74b8221db03a6e4cf8f61
4
- data.tar.gz: 7c3635c0daf967b9567c9c9f92b8ad5b7ec09284
3
+ metadata.gz: 764359a897686829a6256da74c6cb9b09431c145
4
+ data.tar.gz: 326b89336c17823309e87f0892c674d1d3162649
5
5
  SHA512:
6
- metadata.gz: 53ee3848f37877d86f789e8883867b5f4d6daec0f6575df993e291b343829089471b986a529d09da358316c136b824209e47bebb23604d85da57ef26e99e53d4
7
- data.tar.gz: df61e6d8c6551297490450d0001dc2b68691d0008321bfb296d34ed41048fce8f1f0e28163a13b619870c78d13651d8fe2971136e2ae850a5fe1ea85689bf0c2
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.tap do |reply|
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
- try(3) do
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
- private
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 Exception => err
32
+ rescue StandardError => err
52
33
  raise err, "Can't connect to: %s" % @uri
53
34
  end
54
35
 
data/redic.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "redic"
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
  s.summary = "Lightweight Redis Client"
7
7
  s.description = "Lightweight Redis Client"
8
8
  s.authors = ["Michel Martens", "Cyril David"]
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
- assert_raise RuntimeError do
34
- c.call("KABLAMMO")
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.3
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-07 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis