redic 1.1.1 → 1.2.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: de6b1eda9c776a2dbfde7fc9f9f075dc24be294c
4
- data.tar.gz: de83fadd58d193db31d30db2d1d63c46f216131e
3
+ metadata.gz: 1a5382b81b79200b8cfb791f454b9089b06ace3b
4
+ data.tar.gz: 7c893f68df454916127d6b8ef6ab079918745b28
5
5
  SHA512:
6
- metadata.gz: e701f8e6b0870a0cee5ab608e48bf69cb4d2a678bbe61e9aab93a3f02720ba757e510a4692d89a59d5cad3c001eddaf8c1052a47b001e29cfe819daf8e5ad071
7
- data.tar.gz: 937ff72dee2e8f37e13e25b2d7e41d05cd06d929b9121bd305509fd42e1084ca1d254329f21cd6f5b47fbdba21b8a97f20bd8942b1fbfb66833013c86493eb62
6
+ metadata.gz: f0dc33eb8a5874ceda6f206b880feefd7a1ee7c9614620f95adc0d382fdcd225b0223d95c8865aa738239aa5df73f7328bb5fdb70beb236c18a76c56641b7008
7
+ data.tar.gz: 5ae3b1abd97cee063cce9d4bdb29ffe2faae66562251533186a9b2016031a287802f3905cbfd6a1ff429278459300f73ec37fd0791d42e3c0d5635d6e421c066
data/README.md CHANGED
@@ -48,6 +48,13 @@ default timeout is 10 seconds.
48
48
  redis = Redic.new(REDIS_URL, 2_000_000)
49
49
  redis.timeout == 2_000_000 #=> true
50
50
  ```
51
+ A client can be re-configured, forcing the next connection to
52
+ be established with the new details:
53
+
54
+ ```ruby
55
+ redis = Redic.new("redis://localhost:6379")
56
+ redis.configure("redis://localhost:6380")
57
+ ```
51
58
 
52
59
  Here's one final example using both a Redis URL and a timeout:
53
60
 
@@ -61,6 +68,9 @@ REDIS_TIMEOUT = ENV.fetch("REDIS_TIMEOUT")
61
68
  redis = Redic.new(REDIS_URL, REDIS_TIMEOUT)
62
69
  ```
63
70
 
71
+ Both the initializer and the `configure` method accept a `URL` and
72
+ a `timeout`.
73
+
64
74
  ## Differences with redis-rb
65
75
 
66
76
  Redic uses [hiredis][hiredis] for the connection and for parsing
@@ -10,6 +10,11 @@ class Redic
10
10
  @queue = []
11
11
  end
12
12
 
13
+ def configure(url, timeout = 10_000_000)
14
+ @url = url
15
+ @client.configure(url, timeout)
16
+ end
17
+
13
18
  def call(*args)
14
19
  @client.connect do
15
20
  @client.write(args)
@@ -6,10 +6,14 @@ class Redic
6
6
  attr :timeout
7
7
 
8
8
  def initialize(url, timeout)
9
+ @semaphore = Mutex.new
10
+ configure(url, timeout)
11
+ end
12
+
13
+ def configure(url, timeout)
9
14
  @uri = URI.parse(url)
10
15
  @timeout = timeout
11
16
  @connection = nil
12
- @semaphore = Mutex.new
13
17
  end
14
18
 
15
19
  def read
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "redic"
5
- s.version = "1.1.1"
5
+ s.version = "1.2.0"
6
6
  s.summary = "Lightweight Redis Client"
7
7
  s.description = "Lightweight Redis Client"
8
8
  s.authors = ["Michel Martens", "Cyril David"]
@@ -41,12 +41,12 @@ end
41
41
 
42
42
  test "error when authenticating from url" do
43
43
 
44
- # The correct password for 6380 is "foo"
45
- c2 = Redic.new("redis://:foo@localhost:6380/")
44
+ # The correct password for 6381 is "foo"
45
+ c2 = Redic.new("redis://:foo@localhost:6381/")
46
46
  c2.call("PING")
47
47
 
48
48
  # The password provided is wrong
49
- c3 = Redic.new("redis://:bar@localhost:6380/")
49
+ c3 = Redic.new("redis://:bar@localhost:6381/")
50
50
 
51
51
  assert_raise(RuntimeError) do
52
52
 
@@ -173,3 +173,11 @@ test "pub/sub" do |c1|
173
173
 
174
174
  assert_equal "PONG", c1.call("PING")
175
175
  end
176
+
177
+ test "reconnect" do |c1|
178
+ assert_equal "6379", c1.call("INFO", "server").slice(/tcp_port:(\d+)/, 1)
179
+
180
+ c1.configure("redis://:foo@localhost:6381/")
181
+
182
+ assert_equal "6381", c1.call("INFO", "server").slice(/tcp_port:(\d+)/, 1)
183
+ 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.1.1
4
+ version: 1.2.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: 2014-04-23 00:00:00.000000000 Z
12
+ date: 2015-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 2.0.3
68
+ rubygems_version: 2.0.14
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Lightweight Redis Client