redic-sentinels 0.1.0 → 0.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: 54d236a916888c25a0413816ec6e2c649100db9c
4
- data.tar.gz: 62b9e67398198edc52ce30b6956692eeb7f0c7da
3
+ metadata.gz: 00f2c98ea246c4dee97dca3fe3757fec01f0b1e3
4
+ data.tar.gz: 5c871add547ae0d15a034886e5480f284f000e7c
5
5
  SHA512:
6
- metadata.gz: adb8e3aa13617616c2c3979b41ec105956b0473c3d0c16acdc5537b2a36fd5f31c22aef9ad68c8bc68899820bcf3e04ccd2224dd7d859035a7e476e3484ce651
7
- data.tar.gz: 3c5b8d27b12d9585c2a11b2d8c7e924ed5260102c6ebf66b063a40718cae546d06a2234e577d492c82463335c1081243eb1bbad52cdfc62ea3739a484f7faac9
6
+ metadata.gz: 6740acd8892fe316e54a0af8847cb1a110e9e618c461e2c2cd08e68458b06f389e49a2a1cbf24e85146269c50f08d61b922073988e7e74626146534f95fae982
7
+ data.tar.gz: 06188323e825f5db6efe3aac9d2546d1c20491c89ff6b6cccdd1ae543c21a09312b780d4fe7f52e235a43cf276b4143f68cf1b7f4214c126dd3dbf52aedaf9f6
data/README.md CHANGED
@@ -29,13 +29,13 @@ Or install it yourself as:
29
29
  ## Usage
30
30
 
31
31
  ```ruby
32
- sentinels = [
32
+ hosts = [
33
33
  'localhost:26379',
34
34
  'localhost:26380',
35
35
  'localhost:26381'
36
36
  ]
37
37
 
38
- redis = Redic::Sentinels.new sentinels: sentinels,
38
+ redis = Redic::Sentinels.new hosts: hosts,
39
39
  master_name: 'mymaster',
40
40
  db: 1, # optional (default: 0)
41
41
  password: 'pass' # optional
@@ -1,5 +1,5 @@
1
1
  class Redic
2
2
  class Sentinels
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -8,10 +8,10 @@ class Redic
8
8
  class UnreachableHosts < ArgumentError; end
9
9
  class UnknownMaster < ArgumentError; end
10
10
 
11
- attr_reader :hosts, :master_name, :password, :db, :timeout, :client
11
+ attr_reader :hosts, :master_name, :password, :db, :timeout
12
12
 
13
13
  def initialize(options)
14
- @hosts = options.fetch(:hosts)
14
+ @hosts = options.fetch(:hosts)
15
15
  @master_name = options.fetch(:master_name)
16
16
  @password = options[:password]
17
17
  @db = options.fetch(:db, 0)
@@ -21,32 +21,50 @@ class Redic
21
21
  end
22
22
 
23
23
  def call(*args)
24
- forward { client.call *args }
24
+ forward { redis.call *args }
25
25
  end
26
26
 
27
27
  def call!(*args)
28
- forward { client.call! *args }
28
+ forward { redis.call! *args }
29
29
  end
30
30
 
31
31
  def queue(*args)
32
- forward { client.queue *args }
33
- end
34
-
35
- def clear
36
- forward { client.clear }
32
+ forward { redis.queue *args }
37
33
  end
38
34
 
39
35
  def commit
40
- buffer = client.buffer
36
+ buffer = redis.buffer
41
37
 
42
38
  forward do
43
- client.buffer.replace(buffer)
44
- client.commit
39
+ redis.buffer.replace(buffer)
40
+ redis.commit
45
41
  end
46
42
  end
47
43
 
44
+ def buffer
45
+ forward { redis.buffer }
46
+ end
47
+
48
+ def reset
49
+ forward { redis.reset }
50
+ end
51
+
52
+ def clear
53
+ forward { redis.clear }
54
+ end
55
+
56
+ def client
57
+ forward { redis.client }
58
+ end
59
+
60
+ def url
61
+ forward { redis.url }
62
+ end
63
+
48
64
  private
49
65
 
66
+ attr_reader :redis
67
+
50
68
  def forward
51
69
  yield
52
70
  rescue Errno::ECONNREFUSED
@@ -62,7 +80,7 @@ class Redic
62
80
  ip, port = sentinel.call 'SENTINEL', 'get-master-addr-by-name', master_name
63
81
  raise UnknownMaster if ip.nil? && port.nil?
64
82
 
65
- @client = Redic.new "redis://#{password ? ":#{password}@" : ''}#{ip}:#{port}/#{db}"
83
+ @redis = Redic.new *["redis://#{password ? ":#{password}@" : ''}#{ip}:#{port}/#{db}", timeout].compact
66
84
  return
67
85
 
68
86
  rescue Errno::ECONNREFUSED
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
5
+ SimpleCov.start
@@ -1,6 +1,4 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
1
+ require 'coverage_helper'
4
2
  require 'redic-sentinels'
5
3
  require 'minitest/autorun'
6
4
  require 'minitest/colorin'
@@ -18,7 +18,7 @@ describe Redic::Sentinels do
18
18
  MASTER_NAME = 'mymaster'
19
19
 
20
20
  def disconnect(redis)
21
- redis.client.configure "redis://#{INVALID_HOSTS.sample}"
21
+ redis.client.configure "redis://#{INVALID_HOSTS.sample}", 10_000_000
22
22
  end
23
23
 
24
24
  after do
@@ -46,12 +46,18 @@ describe Redic::Sentinels do
46
46
  redis.commit.must_equal ['PONG', 'PONG']
47
47
  end
48
48
 
49
- it 'clear' do
49
+ it 'clear/reset' do
50
50
  redis.queue 'PING'
51
- redis.client.buffer.must_equal [['PING']]
51
+ redis.buffer.must_equal [['PING']]
52
52
 
53
53
  redis.clear
54
- redis.client.buffer.must_be_empty
54
+ redis.buffer.must_be_empty
55
+
56
+ redis.queue 'PING'
57
+ redis.buffer.must_equal [['PING']]
58
+
59
+ redis.reset
60
+ redis.buffer.must_be_empty
55
61
  end
56
62
 
57
63
  it 'get/set' do
@@ -75,17 +81,17 @@ describe Redic::Sentinels do
75
81
  end
76
82
 
77
83
  it 'Default DB' do
78
- redis.client.url.must_equal 'redis://127.0.0.1:16379/0'
84
+ redis.url.must_equal 'redis://127.0.0.1:16379/0'
79
85
  end
80
86
 
81
87
  it 'Custom DB' do
82
88
  redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, db: 7
83
- redis.client.url.must_equal 'redis://127.0.0.1:16379/7'
89
+ redis.url.must_equal 'redis://127.0.0.1:16379/7'
84
90
  end
85
91
 
86
92
  it 'Auth' do
87
93
  redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, password: 'pass'
88
- redis.client.url.must_equal 'redis://:pass@127.0.0.1:16379/0'
94
+ redis.url.must_equal 'redis://:pass@127.0.0.1:16379/0'
89
95
  end
90
96
 
91
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redic-sentinels
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-08 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redic
@@ -162,6 +162,7 @@ files:
162
162
  - lib/redic/sentinels.rb
163
163
  - lib/redic/sentinels/version.rb
164
164
  - redic-sentinels.gemspec
165
+ - spec/coverage_helper.rb
165
166
  - spec/minitest_helper.rb
166
167
  - spec/sentinels_spec.rb
167
168
  homepage: https://github.com/gabynaiman/redic-sentinels
@@ -190,5 +191,6 @@ specification_version: 4
190
191
  summary: Redic::Sentinels is a wrapper for the Redis client that fetches configuration
191
192
  details from sentinels
192
193
  test_files:
194
+ - spec/coverage_helper.rb
193
195
  - spec/minitest_helper.rb
194
196
  - spec/sentinels_spec.rb