redis 4.0.3 → 4.5.0

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