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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9dc763e03ae47f86f5bfeef03c3e6b041a3cefd4
4
- data.tar.gz: 5e0caf8544cd4501df91a4125375bd8ebebf08f3
3
+ metadata.gz: a910a65a110dbb59ba57ac6f9bc012b12b59a1ff
4
+ data.tar.gz: 0b0af9cbf96cb99db9d854b1cc491df57afacffe
5
5
  SHA512:
6
- metadata.gz: adc94f3aaf1b6ea29e735d26ece898d910419f87eb3edcb7998584aedb7a213342254e2e1be0b6dcac12fc6068c8507c84ed1c895c0d89c4f884998194edf143
7
- data.tar.gz: 7a602b0fc1b8dc193b33f3f0d501f9e6eb7f0b550159ea77ec85d690b9599ce0dec279ca553f6d0779e3dc2d7ac461f6cd789c7475f79f434dcc55d19c880712
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.4.5
2
+ hiredis -v 0.6.0
@@ -55,4 +55,8 @@ class Redic
55
55
  def timeout
56
56
  @client.timeout
57
57
  end
58
+
59
+ def quit
60
+ @client.quit
61
+ end
58
62
  end
@@ -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 = nil
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "redic"
5
- s.version = "1.3.0"
5
+ s.version = "1.4.0"
6
6
  s.summary = "Lightweight Redis Client"
7
7
  s.description = "Lightweight Redis Client"
8
8
  s.authors = ["Michel Martens", "Cyril David"]
@@ -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).call("FLUSHDB")
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
- # The correct password for 6381 is "foo"
45
- c2 = Redic.new("redis://:foo@localhost:6381/")
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
- c3 = Redic.new("redis://:bar@localhost:6381/")
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
- c3.call("PING")
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
- assert_equal "6379", c1.call("INFO", "server").slice(/tcp_port:(\d+)/, 1)
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.configure("redis://:foo@localhost:6381/")
205
+ assert_equal true, c1.client.connected?
206
+ assert_equal true, c1.quit
181
207
 
182
- assert_equal "6381", c1.call("INFO", "server").slice(/tcp_port:(\d+)/, 1)
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.3.0
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-02-04 00:00:00.000000000 Z
12
+ date: 2015-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis