redis 3.3.1 → 4.0.1

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.travis/Gemfile +3 -1
  3. data/.travis.yml +36 -52
  4. data/CHANGELOG.md +32 -13
  5. data/Gemfile +0 -1
  6. data/README.md +31 -75
  7. data/benchmarking/logging.rb +1 -1
  8. data/bors.toml +14 -0
  9. data/lib/redis/client.rb +15 -11
  10. data/lib/redis/connection/command_helper.rb +2 -8
  11. data/lib/redis/connection/hiredis.rb +2 -2
  12. data/lib/redis/connection/ruby.rb +18 -20
  13. data/lib/redis/connection/synchrony.rb +12 -4
  14. data/lib/redis/connection.rb +2 -2
  15. data/lib/redis/distributed.rb +21 -8
  16. data/lib/redis/hash_ring.rb +20 -64
  17. data/lib/redis/pipeline.rb +0 -6
  18. data/lib/redis/version.rb +1 -1
  19. data/lib/redis.rb +102 -38
  20. data/makefile +42 -0
  21. data/redis.gemspec +7 -9
  22. data/test/bitpos_test.rb +13 -19
  23. data/test/blocking_commands_test.rb +3 -5
  24. data/test/client_test.rb +1 -1
  25. data/test/command_map_test.rb +3 -5
  26. data/test/commands_on_hashes_test.rb +2 -4
  27. data/test/commands_on_hyper_log_log_test.rb +3 -5
  28. data/test/commands_on_lists_test.rb +2 -4
  29. data/test/commands_on_sets_test.rb +2 -4
  30. data/test/commands_on_sorted_sets_test.rb +17 -4
  31. data/test/commands_on_strings_test.rb +3 -5
  32. data/test/commands_on_value_types_test.rb +44 -6
  33. data/test/connection_handling_test.rb +5 -7
  34. data/test/connection_test.rb +57 -0
  35. data/test/distributed_blocking_commands_test.rb +2 -4
  36. data/test/distributed_commands_on_hashes_test.rb +2 -4
  37. data/test/distributed_commands_on_hyper_log_log_test.rb +2 -4
  38. data/test/distributed_commands_on_lists_test.rb +2 -4
  39. data/test/distributed_commands_on_sets_test.rb +27 -4
  40. data/test/distributed_commands_on_sorted_sets_test.rb +2 -4
  41. data/test/distributed_commands_on_strings_test.rb +20 -10
  42. data/test/distributed_commands_on_value_types_test.rb +2 -4
  43. data/test/distributed_commands_requiring_clustering_test.rb +1 -3
  44. data/test/distributed_connection_handling_test.rb +1 -3
  45. data/test/distributed_internals_test.rb +8 -19
  46. data/test/distributed_key_tags_test.rb +4 -6
  47. data/test/distributed_persistence_control_commands_test.rb +1 -3
  48. data/test/distributed_publish_subscribe_test.rb +1 -3
  49. data/test/distributed_remote_server_control_commands_test.rb +1 -3
  50. data/test/distributed_scripting_test.rb +1 -3
  51. data/test/distributed_sorting_test.rb +1 -3
  52. data/test/distributed_test.rb +12 -14
  53. data/test/distributed_transactions_test.rb +1 -3
  54. data/test/encoding_test.rb +4 -8
  55. data/test/error_replies_test.rb +2 -4
  56. data/test/fork_safety_test.rb +1 -6
  57. data/test/helper.rb +10 -41
  58. data/test/helper_test.rb +1 -3
  59. data/test/internals_test.rb +27 -95
  60. data/test/lint/sets.rb +15 -0
  61. data/test/lint/strings.rb +6 -20
  62. data/test/lint/value_types.rb +8 -0
  63. data/test/persistence_control_commands_test.rb +1 -3
  64. data/test/pipelining_commands_test.rb +4 -8
  65. data/test/publish_subscribe_test.rb +1 -3
  66. data/test/remote_server_control_commands_test.rb +61 -4
  67. data/test/scanning_test.rb +1 -7
  68. data/test/scripting_test.rb +1 -3
  69. data/test/sentinel_command_test.rb +1 -3
  70. data/test/sentinel_test.rb +1 -3
  71. data/test/sorting_test.rb +1 -3
  72. data/test/ssl_test.rb +45 -42
  73. data/test/support/connection/hiredis.rb +1 -1
  74. data/test/support/connection/ruby.rb +1 -1
  75. data/test/support/connection/synchrony.rb +1 -1
  76. data/test/synchrony_driver.rb +6 -9
  77. data/test/thread_safety_test.rb +1 -3
  78. data/test/transactions_test.rb +1 -3
  79. data/test/unknown_commands_test.rb +1 -3
  80. data/test/url_param_test.rb +44 -46
  81. metadata +32 -16
  82. data/Rakefile +0 -87
data/test/helper.rb CHANGED
@@ -1,27 +1,17 @@
1
- $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
- $:.unshift File.expand_path(File.dirname(__FILE__))
3
-
4
1
  require "test/unit"
5
2
  require "logger"
6
3
  require "stringio"
7
4
 
8
- (class Random; def self.rand(*args) super end; end) unless defined?(Random)
9
-
10
- begin
11
- require "ruby-debug"
12
- rescue LoadError
13
- end
14
-
15
5
  $VERBOSE = true
16
6
 
17
- ENV["conn"] ||= "ruby"
7
+ ENV["DRIVER"] ||= "ruby"
18
8
 
19
- require "redis"
20
- require "redis/distributed"
21
- require "redis/connection/#{ENV["conn"]}"
9
+ require_relative "../lib/redis"
10
+ require_relative "../lib/redis/distributed"
11
+ require_relative "../lib/redis/connection/#{ENV["DRIVER"]}"
22
12
 
23
- require "support/redis_mock"
24
- require "support/connection/#{ENV["conn"]}"
13
+ require_relative "support/redis_mock"
14
+ require_relative "support/connection/#{ENV["DRIVER"]}"
25
15
 
26
16
  PORT = 6381
27
17
  OPTIONS = {:port => PORT, :db => 15, :timeout => Float(ENV["TIMEOUT"] || 0.1)}
@@ -44,11 +34,11 @@ def init(redis)
44
34
 
45
35
  Try this once:
46
36
 
47
- $ rake clean
37
+ $ make clean
48
38
 
49
39
  Then run the build again:
50
40
 
51
- $ rake
41
+ $ make
52
42
 
53
43
  EOS
54
44
  exit 1
@@ -56,7 +46,7 @@ def init(redis)
56
46
  end
57
47
 
58
48
  def driver(*drivers, &blk)
59
- if drivers.map(&:to_s).include?(ENV["conn"])
49
+ if drivers.map(&:to_s).include?(ENV["DRIVER"])
60
50
  class_eval(&blk)
61
51
  end
62
52
  end
@@ -92,14 +82,6 @@ module Helper
92
82
  end
93
83
  end
94
84
 
95
- def try_encoding(encoding, &block)
96
- if defined?(Encoding)
97
- with_external_encoding(encoding, &block)
98
- else
99
- yield
100
- end
101
- end
102
-
103
85
  class Version
104
86
 
105
87
  include Comparable
@@ -191,7 +173,7 @@ module Helper
191
173
  end
192
174
 
193
175
  def _new_client(options = {})
194
- Redis.new(_format_options(options).merge(:driver => ENV["conn"]))
176
+ Redis.new(_format_options(options).merge(:driver => ENV["DRIVER"]))
195
177
  end
196
178
  end
197
179
 
@@ -216,17 +198,4 @@ module Helper
216
198
  Redis::Distributed.new(NODES, _format_options(options).merge(:driver => ENV["conn"]))
217
199
  end
218
200
  end
219
-
220
- # Basic support for `skip` in 1.8.x
221
- # Note: YOU MUST use `return skip(message)` in order to appropriately bail
222
- # from a running test.
223
- module Skipable
224
- Skipped = Class.new(RuntimeError)
225
-
226
- def skip(message = nil, bt = caller)
227
- return super if defined?(super)
228
-
229
- $stderr.puts("SKIPPED: #{self} #{message || 'no reason given'}")
230
- end
231
- end
232
201
  end
data/test/helper_test.rb CHANGED
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestHelper < Test::Unit::TestCase
6
4
 
@@ -1,11 +1,8 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestInternals < Test::Unit::TestCase
6
4
 
7
5
  include Helper::Client
8
- include Helper::Skipable
9
6
 
10
7
  def test_logger
11
8
  r.ping
@@ -44,28 +41,24 @@ class TestInternals < Test::Unit::TestCase
44
41
  end
45
42
  end
46
43
 
47
- def test_provides_a_meaningful_inspect
48
- assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
49
- end
50
-
51
44
  def test_redis_current
52
- assert_equal "127.0.0.1", Redis.current.client.host
53
- assert_equal 6379, Redis.current.client.port
54
- assert_equal 0, Redis.current.client.db
45
+ assert_equal "127.0.0.1", Redis.current._client.host
46
+ assert_equal 6379, Redis.current._client.port
47
+ assert_equal 0, Redis.current._client.db
55
48
 
56
49
  Redis.current = Redis.new(OPTIONS.merge(:port => 6380, :db => 1))
57
50
 
58
51
  t = Thread.new do
59
- assert_equal "127.0.0.1", Redis.current.client.host
60
- assert_equal 6380, Redis.current.client.port
61
- assert_equal 1, Redis.current.client.db
52
+ assert_equal "127.0.0.1", Redis.current._client.host
53
+ assert_equal 6380, Redis.current._client.port
54
+ assert_equal 1, Redis.current._client.db
62
55
  end
63
56
 
64
57
  t.join
65
58
 
66
- assert_equal "127.0.0.1", Redis.current.client.host
67
- assert_equal 6380, Redis.current.client.port
68
- assert_equal 1, Redis.current.client.db
59
+ assert_equal "127.0.0.1", Redis.current._client.host
60
+ assert_equal 6380, Redis.current._client.port
61
+ assert_equal 1, Redis.current._client.db
69
62
  end
70
63
 
71
64
  def test_redis_connected?
@@ -79,48 +72,12 @@ class TestInternals < Test::Unit::TestCase
79
72
  assert !fresh_client.connected?
80
73
  end
81
74
 
82
- def test_default_id_with_host_and_port
83
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
84
- assert_equal "redis://host:1234/0", redis.client.id
85
- end
86
-
87
- def test_default_id_with_host_and_port_and_explicit_scheme
88
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
89
- assert_equal "redis://host:1234/0", redis.client.id
90
- end
91
-
92
- def test_default_id_with_path
93
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
94
- assert_equal "redis:///tmp/redis.sock/0", redis.client.id
95
- end
96
-
97
- def test_default_id_with_path_and_explicit_scheme
98
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
99
- assert_equal "redis:///tmp/redis.sock/0", redis.client.id
100
- end
101
-
102
- def test_override_id
103
- redis = Redis.new(OPTIONS.merge(:id => "test"))
104
- assert_equal redis.client.id, "test"
105
- end
106
-
107
75
  def test_timeout
108
76
  assert_nothing_raised do
109
77
  Redis.new(OPTIONS.merge(:timeout => 0))
110
78
  end
111
79
  end
112
80
 
113
- def test_id_inside_multi
114
- redis = Redis.new(OPTIONS)
115
- id = nil
116
-
117
- redis.multi do
118
- id = redis.id
119
- end
120
-
121
- assert_equal id, "redis://127.0.0.1:6381/15"
122
- end
123
-
124
81
  driver(:ruby) do
125
82
  def test_tcp_keepalive
126
83
  keepalive = {:time => 20, :intvl => 10, :probes => 5}
@@ -128,7 +85,7 @@ class TestInternals < Test::Unit::TestCase
128
85
  redis = Redis.new(OPTIONS.merge(:tcp_keepalive => keepalive))
129
86
  redis.ping
130
87
 
131
- connection = redis.client.connection
88
+ connection = redis._client.connection
132
89
  actual_keepalive = connection.get_tcp_keepalive
133
90
 
134
91
  [:time, :intvl, :probes].each do |key|
@@ -161,22 +118,10 @@ class TestInternals < Test::Unit::TestCase
161
118
  assert (Time.now - start_time) <= opts[:timeout]
162
119
  end
163
120
 
164
- driver(:ruby) do
165
- def test_write_timeout
166
- return skip("Relies on buffer sizes, might be unreliable")
167
-
168
- server = TCPServer.new("127.0.0.1", 0)
169
- port = server.addr[1]
170
-
171
- # Hacky, but we need the buffer size
172
- val = TCPSocket.new("127.0.0.1", port).getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).unpack("i")[0]
173
-
174
- assert_raise(Redis::TimeoutError) do
175
- Timeout.timeout(1) do
176
- redis = Redis.new(:port => port, :timeout => 5, :write_timeout => 0.1)
177
- redis.set("foo", "1" * val*2)
178
- end
179
- end
121
+ def test_missing_socket
122
+ opts = { :path => '/missing.sock' }
123
+ assert_raise Redis::CannotConnectError do
124
+ Redis.new(opts).ping
180
125
  end
181
126
  end
182
127
 
@@ -237,7 +182,7 @@ class TestInternals < Test::Unit::TestCase
237
182
  redis.ping
238
183
  end
239
184
 
240
- assert !redis.client.connected?
185
+ assert !redis._client.connected?
241
186
  end
242
187
  end
243
188
 
@@ -253,7 +198,7 @@ class TestInternals < Test::Unit::TestCase
253
198
  redis.ping
254
199
  end
255
200
 
256
- assert !redis.client.connected?
201
+ assert !redis._client.connected?
257
202
  end
258
203
  end
259
204
 
@@ -266,7 +211,7 @@ class TestInternals < Test::Unit::TestCase
266
211
  end
267
212
  end
268
213
 
269
- assert !redis.client.connected?
214
+ assert !redis._client.connected?
270
215
  end
271
216
  end
272
217
 
@@ -307,14 +252,14 @@ class TestInternals < Test::Unit::TestCase
307
252
 
308
253
  def test_retry_on_write_error_by_default
309
254
  close_on_connection([0]) do |redis|
310
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
255
+ assert_equal "1", redis._client.call(["x" * 128 * 1024])
311
256
  end
312
257
  end
313
258
 
314
259
  def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
315
260
  close_on_connection([0]) do |redis|
316
261
  redis.with_reconnect(true) do
317
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
262
+ assert_equal "1", redis._client.call(["x" * 128 * 1024])
318
263
  end
319
264
  end
320
265
  end
@@ -323,7 +268,7 @@ class TestInternals < Test::Unit::TestCase
323
268
  close_on_connection([0]) do |redis|
324
269
  assert_raise Redis::ConnectionError do
325
270
  redis.with_reconnect(false) do
326
- redis.client.call(["x" * 128 * 1024])
271
+ redis._client.call(["x" * 128 * 1024])
327
272
  end
328
273
  end
329
274
  end
@@ -333,7 +278,7 @@ class TestInternals < Test::Unit::TestCase
333
278
  close_on_connection([0]) do |redis|
334
279
  assert_raise Redis::ConnectionError do
335
280
  redis.without_reconnect do
336
- redis.client.call(["x" * 128 * 1024])
281
+ redis._client.call(["x" * 128 * 1024])
337
282
  end
338
283
  end
339
284
  end
@@ -341,7 +286,7 @@ class TestInternals < Test::Unit::TestCase
341
286
 
342
287
  def test_connecting_to_unix_domain_socket
343
288
  assert_nothing_raised do
344
- Redis.new(OPTIONS.merge(:path => "./test/db/redis.sock")).ping
289
+ Redis.new(OPTIONS.merge(:path => ENV.fetch("SOCKET_PATH"))).ping
345
290
  end
346
291
  end
347
292
 
@@ -363,23 +308,10 @@ class TestInternals < Test::Unit::TestCase
363
308
  def test_client_options
364
309
  redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
365
310
 
366
- assert_equal "host", redis.client.options[:host]
367
- assert_equal 1234, redis.client.options[:port]
368
- assert_equal 1, redis.client.options[:db]
369
- assert_equal "foo", redis.client.options[:scheme]
370
- end
371
-
372
- def test_does_not_change_self_client_options
373
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
374
- options = redis.client.options
375
-
376
- options[:host] << "new_host"
377
- options[:scheme] << "bar"
378
- options.merge!(:db => 0)
379
-
380
- assert_equal "host", redis.client.options[:host]
381
- assert_equal 1, redis.client.options[:db]
382
- assert_equal "foo", redis.client.options[:scheme]
311
+ assert_equal "host", redis._client.options[:host]
312
+ assert_equal 1234, redis._client.options[:port]
313
+ assert_equal 1, redis._client.options[:db]
314
+ assert_equal "foo", redis._client.options[:scheme]
383
315
  end
384
316
 
385
317
  def test_resolves_localhost
data/test/lint/sets.rb CHANGED
@@ -52,6 +52,21 @@ module Lint
52
52
  assert_equal nil, r.spop("foo")
53
53
  end
54
54
 
55
+ def test_spop_with_positive_count
56
+ target_version "3.2.0" do
57
+ r.sadd "foo", "s1"
58
+ r.sadd "foo", "s2"
59
+ r.sadd "foo", "s3"
60
+ r.sadd "foo", "s4"
61
+
62
+ pops = r.spop("foo", 3)
63
+
64
+ assert !(["s1", "s2", "s3", "s4"] & pops).empty?
65
+ assert_equal 3, pops.size
66
+ assert_equal 1, r.scard("foo")
67
+ end
68
+ end
69
+
55
70
  def test_scard
56
71
  assert_equal 0, r.scard("foo")
57
72
 
data/test/lint/strings.rb CHANGED
@@ -8,18 +8,6 @@ module Lint
8
8
  assert_equal "s1", r.get("foo")
9
9
  end
10
10
 
11
- def test_set_and_get_with_brackets
12
- r["foo"] = "s1"
13
-
14
- assert_equal "s1", r["foo"]
15
- end
16
-
17
- def test_set_and_get_with_brackets_and_symbol
18
- r[:foo] = "s1"
19
-
20
- assert_equal "s1", r[:foo]
21
- end
22
-
23
11
  def test_set_and_get_with_newline_characters
24
12
  r.set("foo", "1\n")
25
13
 
@@ -35,14 +23,12 @@ module Lint
35
23
  end
36
24
 
37
25
  def test_set_and_get_with_ascii_characters
38
- if defined?(Encoding)
39
- with_external_encoding("ASCII-8BIT") do
40
- (0..255).each do |i|
41
- str = "#{i.chr}---#{i.chr}"
42
- r.set("foo", str)
43
-
44
- assert_equal str, r.get("foo")
45
- end
26
+ with_external_encoding("ASCII-8BIT") do
27
+ (0..255).each do |i|
28
+ str = "#{i.chr}---#{i.chr}"
29
+ r.set("foo", str)
30
+
31
+ assert_equal str, r.get("foo")
46
32
  end
47
33
  end
48
34
  end
@@ -93,6 +93,14 @@ module Lint
93
93
  assert r.restore("bar", 1000, w)
94
94
  assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
95
95
  assert [0, 1].include? r.ttl("bar")
96
+
97
+ r.set("bar", "somethingelse")
98
+ assert_raises(Redis::CommandError) { r.restore("bar", 1000, w) } # ensure by default replace is false
99
+ assert_raises(Redis::CommandError) { r.restore("bar", 1000, w, :replace => false) }
100
+ assert_equal "somethingelse", r.get("bar")
101
+ assert r.restore("bar", 1000, w, :replace => true)
102
+ assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
103
+ assert [0, 1].include? r.ttl("bar")
96
104
  end
97
105
  end
98
106
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestPersistenceControlCommands < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestPipeliningCommands < Test::Unit::TestCase
6
4
 
@@ -136,9 +134,7 @@ class TestPipeliningCommands < Test::Unit::TestCase
136
134
  end
137
135
 
138
136
  assert_equal true, @result.is_a?(Redis::Future)
139
- if defined?(::BasicObject)
140
- assert_equal true, @result.is_a?(::BasicObject)
141
- end
137
+ assert_equal true, @result.is_a?(::BasicObject)
142
138
  assert_equal Redis::Future, @result.class
143
139
  end
144
140
 
@@ -225,7 +221,7 @@ class TestPipeliningCommands < Test::Unit::TestCase
225
221
  p2.select 2
226
222
  end
227
223
 
228
- assert_equal 2, r.client.db
224
+ assert_equal 2, r._client.db
229
225
  end
230
226
 
231
227
  def test_nested_pipeline_select_client_db
@@ -237,6 +233,6 @@ class TestPipeliningCommands < Test::Unit::TestCase
237
233
  end
238
234
  end
239
235
 
240
- assert_equal 3, r.client.db
236
+ assert_equal 3, r._client.db
241
237
  end
242
238
  end
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestPublishSubscribe < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestRemoteServerControlCommands < Test::Unit::TestCase
6
4
 
@@ -101,7 +99,7 @@ class TestRemoteServerControlCommands < Test::Unit::TestCase
101
99
  assert_equal 1, r.object(:refcount, "list")
102
100
  encoding = r.object(:encoding, "list")
103
101
  assert "ziplist" == encoding || "quicklist" == encoding, "Wrong encoding for list"
104
- assert r.object(:idletime, "list").kind_of?(Fixnum)
102
+ assert r.object(:idletime, "list").kind_of?(Integer)
105
103
  end
106
104
 
107
105
  def test_sync
@@ -115,4 +113,63 @@ class TestRemoteServerControlCommands < Test::Unit::TestCase
115
113
  result = r.slowlog(:len)
116
114
  assert_equal 0, result
117
115
  end
116
+
117
+ def test_client
118
+ assert_equal r.instance_variable_get(:@client), r._client
119
+ end
120
+
121
+ def test_client_list
122
+ return if version < "2.4.0"
123
+
124
+ keys = [
125
+ "addr",
126
+ "fd",
127
+ "name",
128
+ "age",
129
+ "idle",
130
+ "flags",
131
+ "db",
132
+ "sub",
133
+ "psub",
134
+ "multi",
135
+ "qbuf",
136
+ "qbuf-free",
137
+ "obl",
138
+ "oll",
139
+ "omem",
140
+ "events",
141
+ "cmd"
142
+ ]
143
+
144
+ clients = r.client(:list)
145
+ clients.each do |client|
146
+ keys.each do |k|
147
+ msg = "expected #client(:list) to include #{k}"
148
+ assert client.keys.include?(k), msg
149
+ end
150
+ end
151
+ end
152
+
153
+ def test_client_kill
154
+ return if version < "2.6.9"
155
+
156
+ r.client(:setname, 'redis-rb')
157
+ clients = r.client(:list)
158
+ i = clients.index {|client| client['name'] == 'redis-rb'}
159
+ assert_equal "OK", r.client(:kill, clients[i]["addr"])
160
+
161
+ clients = r.client(:list)
162
+ i = clients.index {|client| client['name'] == 'redis-rb'}
163
+ assert_equal nil, i
164
+ end
165
+
166
+ def test_client_getname_and_setname
167
+ return if version < "2.6.9"
168
+
169
+ assert_equal nil, r.client(:getname)
170
+
171
+ r.client(:setname, 'redis-rb')
172
+ name = r.client(:getname)
173
+ assert_equal 'redis-rb', name
174
+ end
118
175
  end
@@ -1,10 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- unless defined?(Enumerator)
6
- Enumerator = Enumerable::Enumerator
7
- end
1
+ require_relative "helper"
8
2
 
9
3
  class TestScanning < Test::Unit::TestCase
10
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestScripting < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class SentinelCommandsTest < Test::Unit::TestCase
6
4
 
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class SentinelTest < Test::Unit::TestCase
6
4
 
data/test/sorting_test.rb CHANGED
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestSorting < Test::Unit::TestCase
6
4