redis 3.3.3 → 5.0.5

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 (136) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +280 -12
  3. data/README.md +141 -147
  4. data/lib/redis/client.rb +77 -539
  5. data/lib/redis/commands/bitmaps.rb +66 -0
  6. data/lib/redis/commands/cluster.rb +28 -0
  7. data/lib/redis/commands/connection.rb +53 -0
  8. data/lib/redis/commands/geo.rb +84 -0
  9. data/lib/redis/commands/hashes.rb +254 -0
  10. data/lib/redis/commands/hyper_log_log.rb +37 -0
  11. data/lib/redis/commands/keys.rb +437 -0
  12. data/lib/redis/commands/lists.rb +285 -0
  13. data/lib/redis/commands/pubsub.rb +54 -0
  14. data/lib/redis/commands/scripting.rb +114 -0
  15. data/lib/redis/commands/server.rb +188 -0
  16. data/lib/redis/commands/sets.rb +214 -0
  17. data/lib/redis/commands/sorted_sets.rb +818 -0
  18. data/lib/redis/commands/streams.rb +384 -0
  19. data/lib/redis/commands/strings.rb +314 -0
  20. data/lib/redis/commands/transactions.rb +115 -0
  21. data/lib/redis/commands.rb +235 -0
  22. data/lib/redis/distributed.rb +300 -108
  23. data/lib/redis/errors.rb +22 -1
  24. data/lib/redis/hash_ring.rb +36 -79
  25. data/lib/redis/pipeline.rb +69 -83
  26. data/lib/redis/subscribe.rb +26 -19
  27. data/lib/redis/version.rb +3 -1
  28. data/lib/redis.rb +113 -2685
  29. metadata +40 -218
  30. data/.gitignore +0 -16
  31. data/.travis/Gemfile +0 -11
  32. data/.travis.yml +0 -89
  33. data/.yardopts +0 -3
  34. data/Gemfile +0 -4
  35. data/Rakefile +0 -87
  36. data/benchmarking/logging.rb +0 -71
  37. data/benchmarking/pipeline.rb +0 -51
  38. data/benchmarking/speed.rb +0 -21
  39. data/benchmarking/suite.rb +0 -24
  40. data/benchmarking/worker.rb +0 -71
  41. data/examples/basic.rb +0 -15
  42. data/examples/consistency.rb +0 -114
  43. data/examples/dist_redis.rb +0 -43
  44. data/examples/incr-decr.rb +0 -17
  45. data/examples/list.rb +0 -26
  46. data/examples/pubsub.rb +0 -37
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sentinel.rb +0 -41
  50. data/examples/sets.rb +0 -36
  51. data/examples/unicorn/config.ru +0 -3
  52. data/examples/unicorn/unicorn.rb +0 -20
  53. data/lib/redis/connection/command_helper.rb +0 -44
  54. data/lib/redis/connection/hiredis.rb +0 -66
  55. data/lib/redis/connection/registry.rb +0 -12
  56. data/lib/redis/connection/ruby.rb +0 -429
  57. data/lib/redis/connection/synchrony.rb +0 -133
  58. data/lib/redis/connection.rb +0 -9
  59. data/redis.gemspec +0 -44
  60. data/test/bitpos_test.rb +0 -69
  61. data/test/blocking_commands_test.rb +0 -42
  62. data/test/client_test.rb +0 -59
  63. data/test/command_map_test.rb +0 -30
  64. data/test/commands_on_hashes_test.rb +0 -21
  65. data/test/commands_on_hyper_log_log_test.rb +0 -21
  66. data/test/commands_on_lists_test.rb +0 -20
  67. data/test/commands_on_sets_test.rb +0 -77
  68. data/test/commands_on_sorted_sets_test.rb +0 -137
  69. data/test/commands_on_strings_test.rb +0 -101
  70. data/test/commands_on_value_types_test.rb +0 -133
  71. data/test/connection_handling_test.rb +0 -277
  72. data/test/db/.gitkeep +0 -0
  73. data/test/distributed_blocking_commands_test.rb +0 -46
  74. data/test/distributed_commands_on_hashes_test.rb +0 -10
  75. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  76. data/test/distributed_commands_on_lists_test.rb +0 -22
  77. data/test/distributed_commands_on_sets_test.rb +0 -83
  78. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  79. data/test/distributed_commands_on_strings_test.rb +0 -59
  80. data/test/distributed_commands_on_value_types_test.rb +0 -95
  81. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  82. data/test/distributed_connection_handling_test.rb +0 -23
  83. data/test/distributed_internals_test.rb +0 -79
  84. data/test/distributed_key_tags_test.rb +0 -52
  85. data/test/distributed_persistence_control_commands_test.rb +0 -26
  86. data/test/distributed_publish_subscribe_test.rb +0 -92
  87. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  88. data/test/distributed_scripting_test.rb +0 -102
  89. data/test/distributed_sorting_test.rb +0 -20
  90. data/test/distributed_test.rb +0 -58
  91. data/test/distributed_transactions_test.rb +0 -32
  92. data/test/encoding_test.rb +0 -18
  93. data/test/error_replies_test.rb +0 -59
  94. data/test/fork_safety_test.rb +0 -65
  95. data/test/helper.rb +0 -232
  96. data/test/helper_test.rb +0 -24
  97. data/test/internals_test.rb +0 -457
  98. data/test/lint/blocking_commands.rb +0 -150
  99. data/test/lint/hashes.rb +0 -162
  100. data/test/lint/hyper_log_log.rb +0 -60
  101. data/test/lint/lists.rb +0 -143
  102. data/test/lint/sets.rb +0 -140
  103. data/test/lint/sorted_sets.rb +0 -316
  104. data/test/lint/strings.rb +0 -260
  105. data/test/lint/value_types.rb +0 -122
  106. data/test/persistence_control_commands_test.rb +0 -26
  107. data/test/pipelining_commands_test.rb +0 -242
  108. data/test/publish_subscribe_test.rb +0 -282
  109. data/test/remote_server_control_commands_test.rb +0 -118
  110. data/test/scanning_test.rb +0 -413
  111. data/test/scripting_test.rb +0 -78
  112. data/test/sentinel_command_test.rb +0 -80
  113. data/test/sentinel_test.rb +0 -255
  114. data/test/sorting_test.rb +0 -59
  115. data/test/ssl_test.rb +0 -73
  116. data/test/support/connection/hiredis.rb +0 -1
  117. data/test/support/connection/ruby.rb +0 -1
  118. data/test/support/connection/synchrony.rb +0 -17
  119. data/test/support/redis_mock.rb +0 -130
  120. data/test/support/ssl/gen_certs.sh +0 -31
  121. data/test/support/ssl/trusted-ca.crt +0 -25
  122. data/test/support/ssl/trusted-ca.key +0 -27
  123. data/test/support/ssl/trusted-cert.crt +0 -81
  124. data/test/support/ssl/trusted-cert.key +0 -28
  125. data/test/support/ssl/untrusted-ca.crt +0 -26
  126. data/test/support/ssl/untrusted-ca.key +0 -27
  127. data/test/support/ssl/untrusted-cert.crt +0 -82
  128. data/test/support/ssl/untrusted-cert.key +0 -28
  129. data/test/support/wire/synchrony.rb +0 -24
  130. data/test/support/wire/thread.rb +0 -5
  131. data/test/synchrony_driver.rb +0 -88
  132. data/test/test.conf.erb +0 -9
  133. data/test/thread_safety_test.rb +0 -62
  134. data/test/transactions_test.rb +0 -264
  135. data/test/unknown_commands_test.rb +0 -14
  136. data/test/url_param_test.rb +0 -138
@@ -1,457 +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_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
- 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
55
-
56
- Redis.current = Redis.new(OPTIONS.merge(:port => 6380, :db => 1))
57
-
58
- 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
62
- end
63
-
64
- t.join
65
-
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
69
- end
70
-
71
- def test_redis_connected?
72
- fresh_client = _new_client
73
- assert !fresh_client.connected?
74
-
75
- fresh_client.ping
76
- assert fresh_client.connected?
77
-
78
- fresh_client.quit
79
- assert !fresh_client.connected?
80
- end
81
-
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
- def test_timeout
108
- assert_nothing_raised do
109
- Redis.new(OPTIONS.merge(:timeout => 0))
110
- end
111
- end
112
-
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
- driver(:ruby) do
125
- def test_tcp_keepalive
126
- keepalive = {:time => 20, :intvl => 10, :probes => 5}
127
-
128
- redis = Redis.new(OPTIONS.merge(:tcp_keepalive => keepalive))
129
- redis.ping
130
-
131
- connection = redis.client.connection
132
- actual_keepalive = connection.get_tcp_keepalive
133
-
134
- [:time, :intvl, :probes].each do |key|
135
- if actual_keepalive.has_key?(key)
136
- assert_equal actual_keepalive[key], keepalive[key]
137
- end
138
- end
139
- end
140
- end
141
-
142
- def test_time
143
- target_version "2.5.4" do
144
- # Test that the difference between the time that Ruby reports and the time
145
- # that Redis reports is minimal (prevents the test from being racy).
146
- rv = r.time
147
-
148
- redis_usec = rv[0] * 1_000_000 + rv[1]
149
- ruby_usec = Integer(Time.now.to_f * 1_000_000)
150
-
151
- assert 500_000 > (ruby_usec - redis_usec).abs
152
- end
153
- end
154
-
155
- def test_connection_timeout
156
- opts = OPTIONS.merge(:host => "10.255.255.254", :connect_timeout => 0.1, :timeout => 5.0)
157
- start_time = Time.now
158
- assert_raise Redis::CannotConnectError do
159
- Redis.new(opts).ping
160
- end
161
- assert (Time.now - start_time) <= opts[:timeout]
162
- end
163
-
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
180
- end
181
- end
182
-
183
- def close_on_ping(seq, options = {})
184
- $request = 0
185
-
186
- command = lambda do
187
- idx = $request
188
- $request += 1
189
-
190
- rv = "+%d" % idx
191
- rv = nil if seq.include?(idx)
192
- rv
193
- end
194
-
195
- redis_mock({:ping => command}, {:timeout => 0.1}.merge(options)) do |redis|
196
- yield(redis)
197
- end
198
- end
199
-
200
- def test_retry_by_default
201
- close_on_ping([0]) do |redis|
202
- assert_equal "1", redis.ping
203
- end
204
- end
205
-
206
- def test_retry_when_wrapped_in_with_reconnect_true
207
- close_on_ping([0]) do |redis|
208
- redis.with_reconnect(true) do
209
- assert_equal "1", redis.ping
210
- end
211
- end
212
- end
213
-
214
- def test_dont_retry_when_wrapped_in_with_reconnect_false
215
- close_on_ping([0]) do |redis|
216
- assert_raise Redis::ConnectionError do
217
- redis.with_reconnect(false) do
218
- redis.ping
219
- end
220
- end
221
- end
222
- end
223
-
224
- def test_dont_retry_when_wrapped_in_without_reconnect
225
- close_on_ping([0]) do |redis|
226
- assert_raise Redis::ConnectionError do
227
- redis.without_reconnect do
228
- redis.ping
229
- end
230
- end
231
- end
232
- end
233
-
234
- def test_retry_only_once_when_read_raises_econnreset
235
- close_on_ping([0, 1]) do |redis|
236
- assert_raise Redis::ConnectionError do
237
- redis.ping
238
- end
239
-
240
- assert !redis.client.connected?
241
- end
242
- end
243
-
244
- def test_retry_with_custom_reconnect_attempts
245
- close_on_ping([0, 1], :reconnect_attempts => 2) do |redis|
246
- assert_equal "2", redis.ping
247
- end
248
- end
249
-
250
- def test_retry_with_custom_reconnect_attempts_can_still_fail
251
- close_on_ping([0, 1, 2], :reconnect_attempts => 2) do |redis|
252
- assert_raise Redis::ConnectionError do
253
- redis.ping
254
- end
255
-
256
- assert !redis.client.connected?
257
- end
258
- end
259
-
260
- def test_don_t_retry_when_second_read_in_pipeline_raises_econnreset
261
- close_on_ping([1]) do |redis|
262
- assert_raise Redis::ConnectionError do
263
- redis.pipelined do
264
- redis.ping
265
- redis.ping # Second #read times out
266
- end
267
- end
268
-
269
- assert !redis.client.connected?
270
- end
271
- end
272
-
273
- def close_on_connection(seq)
274
- $n = 0
275
-
276
- read_command = lambda do |session|
277
- Array.new(session.gets[1..-3].to_i) do
278
- bytes = session.gets[1..-3].to_i
279
- arg = session.read(bytes)
280
- session.read(2) # Discard \r\n
281
- arg
282
- end
283
- end
284
-
285
- handler = lambda do |session|
286
- n = $n
287
- $n += 1
288
-
289
- select = read_command.call(session)
290
- if select[0].downcase == "select"
291
- session.write("+OK\r\n")
292
- else
293
- raise "Expected SELECT"
294
- end
295
-
296
- if !seq.include?(n)
297
- while read_command.call(session)
298
- session.write("+#{n}\r\n")
299
- end
300
- end
301
- end
302
-
303
- redis_mock_with_handler(handler) do |redis|
304
- yield(redis)
305
- end
306
- end
307
-
308
- def test_retry_on_write_error_by_default
309
- close_on_connection([0]) do |redis|
310
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
311
- end
312
- end
313
-
314
- def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
315
- close_on_connection([0]) do |redis|
316
- redis.with_reconnect(true) do
317
- assert_equal "1", redis.client.call(["x" * 128 * 1024])
318
- end
319
- end
320
- end
321
-
322
- def test_dont_retry_on_write_error_when_wrapped_in_with_reconnect_false
323
- close_on_connection([0]) do |redis|
324
- assert_raise Redis::ConnectionError do
325
- redis.with_reconnect(false) do
326
- redis.client.call(["x" * 128 * 1024])
327
- end
328
- end
329
- end
330
- end
331
-
332
- def test_dont_retry_on_write_error_when_wrapped_in_without_reconnect
333
- close_on_connection([0]) do |redis|
334
- assert_raise Redis::ConnectionError do
335
- redis.without_reconnect do
336
- redis.client.call(["x" * 128 * 1024])
337
- end
338
- end
339
- end
340
- end
341
-
342
- def test_connecting_to_unix_domain_socket
343
- assert_nothing_raised do
344
- Redis.new(OPTIONS.merge(:path => "./test/db/redis.sock")).ping
345
- end
346
- end
347
-
348
- driver(:ruby, :hiredis) do
349
- def test_bubble_timeout_without_retrying
350
- serv = TCPServer.new(6380)
351
-
352
- redis = Redis.new(:port => 6380, :timeout => 0.1)
353
-
354
- assert_raise(Redis::TimeoutError) do
355
- redis.ping
356
- end
357
-
358
- ensure
359
- serv.close if serv
360
- end
361
- end
362
-
363
- def test_client_options
364
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
365
-
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]
383
- end
384
-
385
- def test_resolves_localhost
386
- assert_nothing_raised do
387
- Redis.new(OPTIONS.merge(:host => 'localhost')).ping
388
- end
389
- end
390
-
391
- class << self
392
- def af_family_supported(af)
393
- hosts = {
394
- Socket::AF_INET => "127.0.0.1",
395
- Socket::AF_INET6 => "::1",
396
- }
397
-
398
- begin
399
- s = Socket.new(af, Socket::SOCK_STREAM, 0)
400
- begin
401
- tries = 5
402
- begin
403
- sa = Socket.pack_sockaddr_in(1024 + Random.rand(63076), hosts[af])
404
- s.bind(sa)
405
- rescue Errno::EADDRINUSE
406
- tries -= 1
407
- retry if tries > 0
408
-
409
- raise
410
- end
411
- yield
412
- rescue Errno::EADDRNOTAVAIL
413
- ensure
414
- s.close
415
- end
416
- rescue Errno::ESOCKTNOSUPPORT
417
- end
418
- end
419
- end
420
-
421
- def af_test(host)
422
- commands = {
423
- :ping => lambda { |*_| "+pong" },
424
- }
425
-
426
- redis_mock(commands, :host => host) do |redis|
427
- assert_nothing_raised do
428
- redis.ping
429
- end
430
- end
431
- end
432
-
433
- driver(:ruby) do
434
- af_family_supported(Socket::AF_INET) do
435
- def test_connect_ipv4
436
- af_test("127.0.0.1")
437
- end
438
- end
439
- end
440
-
441
- driver(:ruby) do
442
- af_family_supported(Socket::AF_INET6) do
443
- def test_connect_ipv6
444
- af_test("::1")
445
- end
446
- end
447
- end
448
-
449
- def test_can_be_duped_to_create_a_new_connection
450
- clients = r.info["connected_clients"].to_i
451
-
452
- r2 = r.dup
453
- r2.ping
454
-
455
- assert_equal clients + 1, r.info["connected_clients"].to_i
456
- end
457
- 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