redis 3.3.5 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +132 -2
  3. data/README.md +144 -79
  4. data/lib/redis.rb +1174 -405
  5. data/lib/redis/client.rb +150 -90
  6. data/lib/redis/cluster.rb +295 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +107 -0
  11. data/lib/redis/cluster/node_key.rb +31 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +93 -0
  14. data/lib/redis/cluster/slot.rb +86 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +4 -2
  17. data/lib/redis/connection/command_helper.rb +5 -10
  18. data/lib/redis/connection/hiredis.rb +6 -5
  19. data/lib/redis/connection/registry.rb +2 -1
  20. data/lib/redis/connection/ruby.rb +126 -128
  21. data/lib/redis/connection/synchrony.rb +21 -8
  22. data/lib/redis/distributed.rb +147 -72
  23. data/lib/redis/errors.rb +48 -0
  24. data/lib/redis/hash_ring.rb +30 -73
  25. data/lib/redis/pipeline.rb +55 -15
  26. data/lib/redis/subscribe.rb +11 -12
  27. data/lib/redis/version.rb +3 -1
  28. metadata +49 -202
  29. data/.gitignore +0 -16
  30. data/.travis.yml +0 -89
  31. data/.travis/Gemfile +0 -11
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -4
  34. data/Rakefile +0 -87
  35. data/benchmarking/logging.rb +0 -71
  36. data/benchmarking/pipeline.rb +0 -51
  37. data/benchmarking/speed.rb +0 -21
  38. data/benchmarking/suite.rb +0 -24
  39. data/benchmarking/worker.rb +0 -71
  40. data/examples/basic.rb +0 -15
  41. data/examples/consistency.rb +0 -114
  42. data/examples/dist_redis.rb +0 -43
  43. data/examples/incr-decr.rb +0 -17
  44. data/examples/list.rb +0 -26
  45. data/examples/pubsub.rb +0 -37
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sets.rb +0 -36
  50. data/examples/unicorn/config.ru +0 -3
  51. data/examples/unicorn/unicorn.rb +0 -20
  52. data/redis.gemspec +0 -44
  53. data/test/bitpos_test.rb +0 -69
  54. data/test/blocking_commands_test.rb +0 -42
  55. data/test/client_test.rb +0 -59
  56. data/test/command_map_test.rb +0 -30
  57. data/test/commands_on_hashes_test.rb +0 -21
  58. data/test/commands_on_hyper_log_log_test.rb +0 -21
  59. data/test/commands_on_lists_test.rb +0 -20
  60. data/test/commands_on_sets_test.rb +0 -77
  61. data/test/commands_on_sorted_sets_test.rb +0 -137
  62. data/test/commands_on_strings_test.rb +0 -101
  63. data/test/commands_on_value_types_test.rb +0 -133
  64. data/test/connection_handling_test.rb +0 -277
  65. data/test/connection_test.rb +0 -57
  66. data/test/db/.gitkeep +0 -0
  67. data/test/distributed_blocking_commands_test.rb +0 -46
  68. data/test/distributed_commands_on_hashes_test.rb +0 -10
  69. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  70. data/test/distributed_commands_on_lists_test.rb +0 -22
  71. data/test/distributed_commands_on_sets_test.rb +0 -83
  72. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  73. data/test/distributed_commands_on_strings_test.rb +0 -59
  74. data/test/distributed_commands_on_value_types_test.rb +0 -95
  75. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  76. data/test/distributed_connection_handling_test.rb +0 -23
  77. data/test/distributed_internals_test.rb +0 -79
  78. data/test/distributed_key_tags_test.rb +0 -52
  79. data/test/distributed_persistence_control_commands_test.rb +0 -26
  80. data/test/distributed_publish_subscribe_test.rb +0 -92
  81. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  82. data/test/distributed_scripting_test.rb +0 -102
  83. data/test/distributed_sorting_test.rb +0 -20
  84. data/test/distributed_test.rb +0 -58
  85. data/test/distributed_transactions_test.rb +0 -32
  86. data/test/encoding_test.rb +0 -18
  87. data/test/error_replies_test.rb +0 -59
  88. data/test/fork_safety_test.rb +0 -65
  89. data/test/helper.rb +0 -232
  90. data/test/helper_test.rb +0 -24
  91. data/test/internals_test.rb +0 -417
  92. data/test/lint/blocking_commands.rb +0 -150
  93. data/test/lint/hashes.rb +0 -162
  94. data/test/lint/hyper_log_log.rb +0 -60
  95. data/test/lint/lists.rb +0 -143
  96. data/test/lint/sets.rb +0 -140
  97. data/test/lint/sorted_sets.rb +0 -316
  98. data/test/lint/strings.rb +0 -260
  99. data/test/lint/value_types.rb +0 -122
  100. data/test/persistence_control_commands_test.rb +0 -26
  101. data/test/pipelining_commands_test.rb +0 -242
  102. data/test/publish_subscribe_test.rb +0 -282
  103. data/test/remote_server_control_commands_test.rb +0 -118
  104. data/test/scanning_test.rb +0 -413
  105. data/test/scripting_test.rb +0 -78
  106. data/test/sentinel_command_test.rb +0 -80
  107. data/test/sentinel_test.rb +0 -255
  108. data/test/sorting_test.rb +0 -59
  109. data/test/ssl_test.rb +0 -73
  110. data/test/support/connection/hiredis.rb +0 -1
  111. data/test/support/connection/ruby.rb +0 -1
  112. data/test/support/connection/synchrony.rb +0 -17
  113. data/test/support/redis_mock.rb +0 -130
  114. data/test/support/ssl/gen_certs.sh +0 -31
  115. data/test/support/ssl/trusted-ca.crt +0 -25
  116. data/test/support/ssl/trusted-ca.key +0 -27
  117. data/test/support/ssl/trusted-cert.crt +0 -81
  118. data/test/support/ssl/trusted-cert.key +0 -28
  119. data/test/support/ssl/untrusted-ca.crt +0 -26
  120. data/test/support/ssl/untrusted-ca.key +0 -27
  121. data/test/support/ssl/untrusted-cert.crt +0 -82
  122. data/test/support/ssl/untrusted-cert.key +0 -28
  123. data/test/support/wire/synchrony.rb +0 -24
  124. data/test/support/wire/thread.rb +0 -5
  125. data/test/synchrony_driver.rb +0 -88
  126. data/test/test.conf.erb +0 -9
  127. data/test/thread_safety_test.rb +0 -62
  128. data/test/transactions_test.rb +0 -264
  129. data/test/unknown_commands_test.rb +0 -14
  130. data/test/url_param_test.rb +0 -138
data/test/helper_test.rb DELETED
@@ -1,24 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestHelper < Test::Unit::TestCase
6
-
7
- include Helper
8
-
9
- def test_version_comparison
10
- v = Version.new("2.0.1")
11
-
12
- assert v > "1"
13
- assert v > "2"
14
- assert v < "3"
15
- assert v < "10"
16
-
17
- assert v < "2.1"
18
- assert v < "2.0.2"
19
- assert v < "2.0.1.1"
20
- assert v < "2.0.10"
21
-
22
- assert v == "2.0.1"
23
- end
24
- end
@@ -1,417 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestInternals < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
- include Helper::Skipable
9
-
10
- def test_logger
11
- r.ping
12
-
13
- assert log.string["[Redis] command=PING"]
14
- assert log.string =~ /\[Redis\] call_time=\d+\.\d+ ms/
15
- end
16
-
17
- def test_logger_with_pipelining
18
- r.pipelined do
19
- r.set "foo", "bar"
20
- r.get "foo"
21
- end
22
-
23
- assert log.string[" command=SET args=\"foo\" \"bar\""]
24
- assert log.string[" command=GET args=\"foo\""]
25
- end
26
-
27
- def test_recovers_from_failed_commands
28
- # See https://github.com/redis/redis-rb/issues#issue/28
29
-
30
- assert_raise(Redis::CommandError) do
31
- r.command_that_doesnt_exist
32
- end
33
-
34
- assert_nothing_raised do
35
- r.info
36
- end
37
- end
38
-
39
- def test_raises_on_protocol_errors
40
- redis_mock(:ping => lambda { |*_| "foo" }) do |redis|
41
- assert_raise(Redis::ProtocolError) do
42
- redis.ping
43
- end
44
- end
45
- end
46
-
47
- def test_redis_current
48
- assert_equal "127.0.0.1", Redis.current.client.host
49
- assert_equal 6379, Redis.current.client.port
50
- assert_equal 0, Redis.current.client.db
51
-
52
- Redis.current = Redis.new(OPTIONS.merge(:port => 6380, :db => 1))
53
-
54
- t = Thread.new do
55
- assert_equal "127.0.0.1", Redis.current.client.host
56
- assert_equal 6380, Redis.current.client.port
57
- assert_equal 1, Redis.current.client.db
58
- end
59
-
60
- t.join
61
-
62
- assert_equal "127.0.0.1", Redis.current.client.host
63
- assert_equal 6380, Redis.current.client.port
64
- assert_equal 1, Redis.current.client.db
65
- end
66
-
67
- def test_redis_connected?
68
- fresh_client = _new_client
69
- assert !fresh_client.connected?
70
-
71
- fresh_client.ping
72
- assert fresh_client.connected?
73
-
74
- fresh_client.quit
75
- assert !fresh_client.connected?
76
- end
77
-
78
- def test_timeout
79
- assert_nothing_raised do
80
- Redis.new(OPTIONS.merge(:timeout => 0))
81
- end
82
- end
83
-
84
- driver(:ruby) do
85
- def test_tcp_keepalive
86
- keepalive = {:time => 20, :intvl => 10, :probes => 5}
87
-
88
- redis = Redis.new(OPTIONS.merge(:tcp_keepalive => keepalive))
89
- redis.ping
90
-
91
- connection = redis.client.connection
92
- actual_keepalive = connection.get_tcp_keepalive
93
-
94
- [:time, :intvl, :probes].each do |key|
95
- if actual_keepalive.has_key?(key)
96
- assert_equal actual_keepalive[key], keepalive[key]
97
- end
98
- end
99
- end
100
- end
101
-
102
- def test_time
103
- target_version "2.5.4" do
104
- # Test that the difference between the time that Ruby reports and the time
105
- # that Redis reports is minimal (prevents the test from being racy).
106
- rv = r.time
107
-
108
- redis_usec = rv[0] * 1_000_000 + rv[1]
109
- ruby_usec = Integer(Time.now.to_f * 1_000_000)
110
-
111
- assert 500_000 > (ruby_usec - redis_usec).abs
112
- end
113
- end
114
-
115
- def test_connection_timeout
116
- opts = OPTIONS.merge(:host => "10.255.255.254", :connect_timeout => 0.1, :timeout => 5.0)
117
- start_time = Time.now
118
- assert_raise Redis::CannotConnectError do
119
- Redis.new(opts).ping
120
- end
121
- assert (Time.now - start_time) <= opts[:timeout]
122
- end
123
-
124
- driver(:ruby) do
125
- def test_write_timeout
126
- return skip("Relies on buffer sizes, might be unreliable")
127
-
128
- server = TCPServer.new("127.0.0.1", 0)
129
- port = server.addr[1]
130
-
131
- # Hacky, but we need the buffer size
132
- val = TCPSocket.new("127.0.0.1", port).getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).unpack("i")[0]
133
-
134
- assert_raise(Redis::TimeoutError) do
135
- Timeout.timeout(1) do
136
- redis = Redis.new(:port => port, :timeout => 5, :write_timeout => 0.1)
137
- redis.set("foo", "1" * val*2)
138
- end
139
- end
140
- end
141
- end
142
-
143
- def close_on_ping(seq, options = {})
144
- $request = 0
145
-
146
- command = lambda do
147
- idx = $request
148
- $request += 1
149
-
150
- rv = "+%d" % idx
151
- rv = nil if seq.include?(idx)
152
- rv
153
- end
154
-
155
- redis_mock({:ping => command}, {:timeout => 0.1}.merge(options)) do |redis|
156
- yield(redis)
157
- end
158
- end
159
-
160
- def test_retry_by_default
161
- close_on_ping([0]) do |redis|
162
- assert_equal "1", redis.ping
163
- end
164
- end
165
-
166
- def test_retry_when_wrapped_in_with_reconnect_true
167
- close_on_ping([0]) do |redis|
168
- redis.with_reconnect(true) do
169
- assert_equal "1", redis.ping
170
- end
171
- end
172
- end
173
-
174
- def test_dont_retry_when_wrapped_in_with_reconnect_false
175
- close_on_ping([0]) do |redis|
176
- assert_raise Redis::ConnectionError do
177
- redis.with_reconnect(false) do
178
- redis.ping
179
- end
180
- end
181
- end
182
- end
183
-
184
- def test_dont_retry_when_wrapped_in_without_reconnect
185
- close_on_ping([0]) do |redis|
186
- assert_raise Redis::ConnectionError do
187
- redis.without_reconnect do
188
- redis.ping
189
- end
190
- end
191
- end
192
- end
193
-
194
- def test_retry_only_once_when_read_raises_econnreset
195
- close_on_ping([0, 1]) do |redis|
196
- assert_raise Redis::ConnectionError do
197
- redis.ping
198
- end
199
-
200
- assert !redis.client.connected?
201
- end
202
- end
203
-
204
- def test_retry_with_custom_reconnect_attempts
205
- close_on_ping([0, 1], :reconnect_attempts => 2) do |redis|
206
- assert_equal "2", redis.ping
207
- end
208
- end
209
-
210
- def test_retry_with_custom_reconnect_attempts_can_still_fail
211
- close_on_ping([0, 1, 2], :reconnect_attempts => 2) do |redis|
212
- assert_raise Redis::ConnectionError do
213
- redis.ping
214
- end
215
-
216
- assert !redis.client.connected?
217
- end
218
- end
219
-
220
- def test_don_t_retry_when_second_read_in_pipeline_raises_econnreset
221
- close_on_ping([1]) do |redis|
222
- assert_raise Redis::ConnectionError do
223
- redis.pipelined do
224
- redis.ping
225
- redis.ping # Second #read times out
226
- end
227
- end
228
-
229
- assert !redis.client.connected?
230
- end
231
- end
232
-
233
- def close_on_connection(seq)
234
- $n = 0
235
-
236
- read_command = lambda do |session|
237
- Array.new(session.gets[1..-3].to_i) do
238
- bytes = session.gets[1..-3].to_i
239
- arg = session.read(bytes)
240
- session.read(2) # Discard \r\n
241
- arg
242
- end
243
- end
244
-
245
- handler = lambda do |session|
246
- n = $n
247
- $n += 1
248
-
249
- select = read_command.call(session)
250
- if select[0].downcase == "select"
251
- session.write("+OK\r\n")
252
- else
253
- raise "Expected SELECT"
254
- end
255
-
256
- if !seq.include?(n)
257
- while read_command.call(session)
258
- session.write("+#{n}\r\n")
259
- end
260
- end
261
- end
262
-
263
- redis_mock_with_handler(handler) do |redis|
264
- yield(redis)
265
- end
266
- end
267
-
268
- def test_retry_on_write_error_by_default
269
- close_on_connection([0]) do |redis|
270
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
271
- end
272
- end
273
-
274
- def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
275
- close_on_connection([0]) do |redis|
276
- redis.with_reconnect(true) do
277
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
278
- end
279
- end
280
- end
281
-
282
- def test_dont_retry_on_write_error_when_wrapped_in_with_reconnect_false
283
- close_on_connection([0]) do |redis|
284
- assert_raise Redis::ConnectionError do
285
- redis.with_reconnect(false) do
286
- redis.client.call(["x" * 128 * 1024])
287
- end
288
- end
289
- end
290
- end
291
-
292
- def test_dont_retry_on_write_error_when_wrapped_in_without_reconnect
293
- close_on_connection([0]) do |redis|
294
- assert_raise Redis::ConnectionError do
295
- redis.without_reconnect do
296
- redis.client.call(["x" * 128 * 1024])
297
- end
298
- end
299
- end
300
- end
301
-
302
- def test_connecting_to_unix_domain_socket
303
- assert_nothing_raised do
304
- Redis.new(OPTIONS.merge(:path => "./test/db/redis.sock")).ping
305
- end
306
- end
307
-
308
- driver(:ruby, :hiredis) do
309
- def test_bubble_timeout_without_retrying
310
- serv = TCPServer.new(6380)
311
-
312
- redis = Redis.new(:port => 6380, :timeout => 0.1)
313
-
314
- assert_raise(Redis::TimeoutError) do
315
- redis.ping
316
- end
317
-
318
- ensure
319
- serv.close if serv
320
- end
321
- end
322
-
323
- def test_client_options
324
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
325
-
326
- assert_equal "host", redis.client.options[:host]
327
- assert_equal 1234, redis.client.options[:port]
328
- assert_equal 1, redis.client.options[:db]
329
- assert_equal "foo", redis.client.options[:scheme]
330
- end
331
-
332
- def test_does_not_change_self_client_options
333
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
334
- options = redis.client.options
335
-
336
- options[:host] << "new_host"
337
- options[:scheme] << "bar"
338
- options.merge!(:db => 0)
339
-
340
- assert_equal "host", redis.client.options[:host]
341
- assert_equal 1, redis.client.options[:db]
342
- assert_equal "foo", redis.client.options[:scheme]
343
- end
344
-
345
- def test_resolves_localhost
346
- assert_nothing_raised do
347
- Redis.new(OPTIONS.merge(:host => 'localhost')).ping
348
- end
349
- end
350
-
351
- class << self
352
- def af_family_supported(af)
353
- hosts = {
354
- Socket::AF_INET => "127.0.0.1",
355
- Socket::AF_INET6 => "::1",
356
- }
357
-
358
- begin
359
- s = Socket.new(af, Socket::SOCK_STREAM, 0)
360
- begin
361
- tries = 5
362
- begin
363
- sa = Socket.pack_sockaddr_in(1024 + Random.rand(63076), hosts[af])
364
- s.bind(sa)
365
- rescue Errno::EADDRINUSE
366
- tries -= 1
367
- retry if tries > 0
368
-
369
- raise
370
- end
371
- yield
372
- rescue Errno::EADDRNOTAVAIL
373
- ensure
374
- s.close
375
- end
376
- rescue Errno::ESOCKTNOSUPPORT
377
- end
378
- end
379
- end
380
-
381
- def af_test(host)
382
- commands = {
383
- :ping => lambda { |*_| "+pong" },
384
- }
385
-
386
- redis_mock(commands, :host => host) do |redis|
387
- assert_nothing_raised do
388
- redis.ping
389
- end
390
- end
391
- end
392
-
393
- driver(:ruby) do
394
- af_family_supported(Socket::AF_INET) do
395
- def test_connect_ipv4
396
- af_test("127.0.0.1")
397
- end
398
- end
399
- end
400
-
401
- driver(:ruby) do
402
- af_family_supported(Socket::AF_INET6) do
403
- def test_connect_ipv6
404
- af_test("::1")
405
- end
406
- end
407
- end
408
-
409
- def test_can_be_duped_to_create_a_new_connection
410
- clients = r.info["connected_clients"].to_i
411
-
412
- r2 = r.dup
413
- r2.ping
414
-
415
- assert_equal clients + 1, r.info["connected_clients"].to_i
416
- end
417
- end
@@ -1,150 +0,0 @@
1
- module Lint
2
-
3
- module BlockingCommands
4
-
5
- def setup
6
- super
7
-
8
- r.rpush("{zap}foo", "s1")
9
- r.rpush("{zap}foo", "s2")
10
- r.rpush("{zap}bar", "s1")
11
- r.rpush("{zap}bar", "s2")
12
- end
13
-
14
- def to_protocol(obj)
15
- case obj
16
- when String
17
- "$#{obj.length}\r\n#{obj}\r\n"
18
- when Array
19
- "*#{obj.length}\r\n" + obj.map { |e| to_protocol(e) }.join
20
- else
21
- fail
22
- end
23
- end
24
-
25
- def mock(options = {}, &blk)
26
- commands = {
27
- :blpop => lambda do |*args|
28
- sleep options[:delay] if options.has_key?(:delay)
29
- to_protocol([args.first, args.last])
30
- end,
31
- :brpop => lambda do |*args|
32
- sleep options[:delay] if options.has_key?(:delay)
33
- to_protocol([args.first, args.last])
34
- end,
35
- :brpoplpush => lambda do |*args|
36
- sleep options[:delay] if options.has_key?(:delay)
37
- to_protocol(args.last)
38
- end
39
- }
40
-
41
- redis_mock(commands, &blk)
42
- end
43
-
44
- def test_blpop
45
- assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo")
46
- assert_equal ["{zap}foo", "s2"], r.blpop(["{zap}foo"])
47
- assert_equal ["{zap}bar", "s1"], r.blpop(["{zap}bar", "{zap}foo"])
48
- assert_equal ["{zap}bar", "s2"], r.blpop(["{zap}foo", "{zap}bar"])
49
- end
50
-
51
- def test_blpop_timeout
52
- mock do |r|
53
- assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo")
54
- assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", :timeout => 1)
55
- end
56
- end
57
-
58
- def test_blpop_with_old_prototype
59
- assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo", 0)
60
- assert_equal ["{zap}foo", "s2"], r.blpop("{zap}foo", 0)
61
- assert_equal ["{zap}bar", "s1"], r.blpop("{zap}bar", "{zap}foo", 0)
62
- assert_equal ["{zap}bar", "s2"], r.blpop("{zap}foo", "{zap}bar", 0)
63
- end
64
-
65
- def test_blpop_timeout_with_old_prototype
66
- mock do |r|
67
- assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo", 0)
68
- assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", 1)
69
- end
70
- end
71
-
72
- def test_brpop
73
- assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo")
74
- assert_equal ["{zap}foo", "s1"], r.brpop(["{zap}foo"])
75
- assert_equal ["{zap}bar", "s2"], r.brpop(["{zap}bar", "{zap}foo"])
76
- assert_equal ["{zap}bar", "s1"], r.brpop(["{zap}foo", "{zap}bar"])
77
- end
78
-
79
- def test_brpop_timeout
80
- mock do |r|
81
- assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo")
82
- assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", :timeout => 1)
83
- end
84
- end
85
-
86
- def test_brpop_with_old_prototype
87
- assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo", 0)
88
- assert_equal ["{zap}foo", "s1"], r.brpop("{zap}foo", 0)
89
- assert_equal ["{zap}bar", "s2"], r.brpop("{zap}bar", "{zap}foo", 0)
90
- assert_equal ["{zap}bar", "s1"], r.brpop("{zap}foo", "{zap}bar", 0)
91
- end
92
-
93
- def test_brpop_timeout_with_old_prototype
94
- mock do |r|
95
- assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo", 0)
96
- assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", 1)
97
- end
98
- end
99
-
100
- def test_brpoplpush
101
- assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux")
102
- assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
103
- end
104
-
105
- def test_brpoplpush_timeout
106
- mock do |r|
107
- assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar")
108
- assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", :timeout => 1)
109
- end
110
- end
111
-
112
- def test_brpoplpush_with_old_prototype
113
- assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux", 0)
114
- assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
115
- end
116
-
117
- def test_brpoplpush_timeout_with_old_prototype
118
- mock do |r|
119
- assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar", 0)
120
- assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", 1)
121
- end
122
- end
123
-
124
- driver(:ruby, :hiredis) do
125
- def test_blpop_socket_timeout
126
- mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
127
- assert_raises(Redis::TimeoutError) do
128
- r.blpop("{zap}foo", :timeout => 1)
129
- end
130
- end
131
- end
132
-
133
- def test_brpop_socket_timeout
134
- mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
135
- assert_raises(Redis::TimeoutError) do
136
- r.brpop("{zap}foo", :timeout => 1)
137
- end
138
- end
139
- end
140
-
141
- def test_brpoplpush_socket_timeout
142
- mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
143
- assert_raises(Redis::TimeoutError) do
144
- r.brpoplpush("{zap}foo", "{zap}bar", :timeout => 1)
145
- end
146
- end
147
- end
148
- end
149
- end
150
- end