redis 4.1.0.beta1 → 4.1.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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +45 -0
  4. data/lib/redis.rb +497 -20
  5. data/lib/redis/client.rb +14 -6
  6. data/lib/redis/cluster.rb +1 -0
  7. data/lib/redis/cluster/command_loader.rb +2 -0
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +1 -0
  10. data/lib/redis/cluster/slot_loader.rb +2 -0
  11. data/lib/redis/distributed.rb +3 -4
  12. data/lib/redis/version.rb +1 -1
  13. metadata +20 -243
  14. data/.gitignore +0 -19
  15. data/.travis.yml +0 -61
  16. data/.travis/Gemfile +0 -18
  17. data/.yardopts +0 -3
  18. data/Gemfile +0 -8
  19. data/benchmarking/logging.rb +0 -71
  20. data/benchmarking/pipeline.rb +0 -51
  21. data/benchmarking/speed.rb +0 -21
  22. data/benchmarking/suite.rb +0 -24
  23. data/benchmarking/worker.rb +0 -71
  24. data/bin/build +0 -71
  25. data/bors.toml +0 -14
  26. data/examples/basic.rb +0 -15
  27. data/examples/consistency.rb +0 -114
  28. data/examples/dist_redis.rb +0 -43
  29. data/examples/incr-decr.rb +0 -17
  30. data/examples/list.rb +0 -26
  31. data/examples/pubsub.rb +0 -37
  32. data/examples/sentinel.rb +0 -41
  33. data/examples/sentinel/start +0 -49
  34. data/examples/sets.rb +0 -36
  35. data/examples/unicorn/config.ru +0 -3
  36. data/examples/unicorn/unicorn.rb +0 -20
  37. data/makefile +0 -74
  38. data/redis.gemspec +0 -42
  39. data/test/bitpos_test.rb +0 -63
  40. data/test/blocking_commands_test.rb +0 -40
  41. data/test/client_test.rb +0 -76
  42. data/test/cluster_abnormal_state_test.rb +0 -38
  43. data/test/cluster_blocking_commands_test.rb +0 -15
  44. data/test/cluster_client_internals_test.rb +0 -77
  45. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  46. data/test/cluster_client_options_test.rb +0 -147
  47. data/test/cluster_client_pipelining_test.rb +0 -59
  48. data/test/cluster_client_replicas_test.rb +0 -36
  49. data/test/cluster_client_slots_test.rb +0 -94
  50. data/test/cluster_client_transactions_test.rb +0 -71
  51. data/test/cluster_commands_on_cluster_test.rb +0 -165
  52. data/test/cluster_commands_on_connection_test.rb +0 -40
  53. data/test/cluster_commands_on_geo_test.rb +0 -74
  54. data/test/cluster_commands_on_hashes_test.rb +0 -11
  55. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  56. data/test/cluster_commands_on_keys_test.rb +0 -134
  57. data/test/cluster_commands_on_lists_test.rb +0 -15
  58. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  59. data/test/cluster_commands_on_scripting_test.rb +0 -56
  60. data/test/cluster_commands_on_server_test.rb +0 -221
  61. data/test/cluster_commands_on_sets_test.rb +0 -39
  62. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  63. data/test/cluster_commands_on_streams_test.rb +0 -196
  64. data/test/cluster_commands_on_strings_test.rb +0 -15
  65. data/test/cluster_commands_on_transactions_test.rb +0 -41
  66. data/test/cluster_commands_on_value_types_test.rb +0 -14
  67. data/test/command_map_test.rb +0 -28
  68. data/test/commands_on_geo_test.rb +0 -116
  69. data/test/commands_on_hashes_test.rb +0 -7
  70. data/test/commands_on_hyper_log_log_test.rb +0 -7
  71. data/test/commands_on_lists_test.rb +0 -7
  72. data/test/commands_on_sets_test.rb +0 -7
  73. data/test/commands_on_sorted_sets_test.rb +0 -7
  74. data/test/commands_on_strings_test.rb +0 -7
  75. data/test/commands_on_value_types_test.rb +0 -207
  76. data/test/connection_handling_test.rb +0 -275
  77. data/test/connection_test.rb +0 -57
  78. data/test/distributed_blocking_commands_test.rb +0 -52
  79. data/test/distributed_commands_on_hashes_test.rb +0 -21
  80. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  81. data/test/distributed_commands_on_lists_test.rb +0 -19
  82. data/test/distributed_commands_on_sets_test.rb +0 -105
  83. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  84. data/test/distributed_commands_on_strings_test.rb +0 -79
  85. data/test/distributed_commands_on_value_types_test.rb +0 -129
  86. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  87. data/test/distributed_connection_handling_test.rb +0 -21
  88. data/test/distributed_internals_test.rb +0 -68
  89. data/test/distributed_key_tags_test.rb +0 -50
  90. data/test/distributed_persistence_control_commands_test.rb +0 -24
  91. data/test/distributed_publish_subscribe_test.rb +0 -90
  92. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  93. data/test/distributed_scripting_test.rb +0 -100
  94. data/test/distributed_sorting_test.rb +0 -18
  95. data/test/distributed_test.rb +0 -56
  96. data/test/distributed_transactions_test.rb +0 -30
  97. data/test/encoding_test.rb +0 -14
  98. data/test/error_replies_test.rb +0 -57
  99. data/test/fork_safety_test.rb +0 -60
  100. data/test/helper.rb +0 -344
  101. data/test/helper_test.rb +0 -22
  102. data/test/internals_test.rb +0 -395
  103. data/test/lint/blocking_commands.rb +0 -174
  104. data/test/lint/hashes.rb +0 -203
  105. data/test/lint/hyper_log_log.rb +0 -74
  106. data/test/lint/lists.rb +0 -159
  107. data/test/lint/sets.rb +0 -282
  108. data/test/lint/sorted_sets.rb +0 -497
  109. data/test/lint/strings.rb +0 -348
  110. data/test/lint/value_types.rb +0 -130
  111. data/test/persistence_control_commands_test.rb +0 -24
  112. data/test/pipelining_commands_test.rb +0 -246
  113. data/test/publish_subscribe_test.rb +0 -280
  114. data/test/remote_server_control_commands_test.rb +0 -175
  115. data/test/scanning_test.rb +0 -407
  116. data/test/scripting_test.rb +0 -76
  117. data/test/sentinel_command_test.rb +0 -78
  118. data/test/sentinel_test.rb +0 -253
  119. data/test/sorting_test.rb +0 -57
  120. data/test/ssl_test.rb +0 -69
  121. data/test/support/cluster/orchestrator.rb +0 -199
  122. data/test/support/connection/hiredis.rb +0 -1
  123. data/test/support/connection/ruby.rb +0 -1
  124. data/test/support/connection/synchrony.rb +0 -17
  125. data/test/support/redis_mock.rb +0 -130
  126. data/test/support/ssl/gen_certs.sh +0 -31
  127. data/test/support/ssl/trusted-ca.crt +0 -25
  128. data/test/support/ssl/trusted-ca.key +0 -27
  129. data/test/support/ssl/trusted-cert.crt +0 -81
  130. data/test/support/ssl/trusted-cert.key +0 -28
  131. data/test/support/ssl/untrusted-ca.crt +0 -26
  132. data/test/support/ssl/untrusted-ca.key +0 -27
  133. data/test/support/ssl/untrusted-cert.crt +0 -82
  134. data/test/support/ssl/untrusted-cert.key +0 -28
  135. data/test/support/wire/synchrony.rb +0 -24
  136. data/test/support/wire/thread.rb +0 -5
  137. data/test/synchrony_driver.rb +0 -85
  138. data/test/test.conf.erb +0 -9
  139. data/test/thread_safety_test.rb +0 -60
  140. data/test/transactions_test.rb +0 -272
  141. data/test/unknown_commands_test.rb +0 -12
  142. data/test/url_param_test.rb +0 -136
@@ -1,22 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestHelper < Test::Unit::TestCase
4
-
5
- include Helper
6
-
7
- def test_version_comparison
8
- v = Version.new("2.0.1")
9
-
10
- assert v > "1"
11
- assert v > "2"
12
- assert v < "3"
13
- assert v < "10"
14
-
15
- assert v < "2.1"
16
- assert v < "2.0.2"
17
- assert v < "2.0.1.1"
18
- assert v < "2.0.10"
19
-
20
- assert v == "2.0.1"
21
- end
22
- end
@@ -1,395 +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_don_t_retry_when_second_read_in_pipeline_raises_econnreset
206
- close_on_ping([1]) do |redis|
207
- assert_raise Redis::ConnectionError do
208
- redis.pipelined do
209
- redis.ping
210
- redis.ping # Second #read times out
211
- end
212
- end
213
-
214
- assert !redis._client.connected?
215
- end
216
- end
217
-
218
- def close_on_connection(seq)
219
- $n = 0
220
-
221
- read_command = lambda do |session|
222
- Array.new(session.gets[1..-3].to_i) do
223
- bytes = session.gets[1..-3].to_i
224
- arg = session.read(bytes)
225
- session.read(2) # Discard \r\n
226
- arg
227
- end
228
- end
229
-
230
- handler = lambda do |session|
231
- n = $n
232
- $n += 1
233
-
234
- select = read_command.call(session)
235
- if select[0].downcase == "select"
236
- session.write("+OK\r\n")
237
- else
238
- raise "Expected SELECT"
239
- end
240
-
241
- if !seq.include?(n)
242
- while read_command.call(session)
243
- session.write("+#{n}\r\n")
244
- end
245
- end
246
- end
247
-
248
- redis_mock_with_handler(handler) do |redis|
249
- yield(redis)
250
- end
251
- end
252
-
253
- def test_retry_on_write_error_by_default
254
- close_on_connection([0]) do |redis|
255
- assert_equal "1", redis._client.call(["x" * 128 * 1024])
256
- end
257
- end
258
-
259
- def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
260
- close_on_connection([0]) do |redis|
261
- redis.with_reconnect(true) do
262
- assert_equal "1", redis._client.call(["x" * 128 * 1024])
263
- end
264
- end
265
- end
266
-
267
- def test_dont_retry_on_write_error_when_wrapped_in_with_reconnect_false
268
- close_on_connection([0]) do |redis|
269
- assert_raise Redis::ConnectionError do
270
- redis.with_reconnect(false) do
271
- redis._client.call(["x" * 128 * 1024])
272
- end
273
- end
274
- end
275
- end
276
-
277
- def test_dont_retry_on_write_error_when_wrapped_in_without_reconnect
278
- close_on_connection([0]) do |redis|
279
- assert_raise Redis::ConnectionError do
280
- redis.without_reconnect do
281
- redis._client.call(["x" * 128 * 1024])
282
- end
283
- end
284
- end
285
- end
286
-
287
- def test_connecting_to_unix_domain_socket
288
- assert_nothing_raised do
289
- Redis.new(OPTIONS.merge(:path => ENV.fetch("SOCKET_PATH"))).ping
290
- end
291
- end
292
-
293
- driver(:ruby, :hiredis) do
294
- def test_bubble_timeout_without_retrying
295
- serv = TCPServer.new(6380)
296
-
297
- redis = Redis.new(:port => 6380, :timeout => 0.1)
298
-
299
- assert_raise(Redis::TimeoutError) do
300
- redis.ping
301
- end
302
-
303
- ensure
304
- serv.close if serv
305
- end
306
- end
307
-
308
- def test_client_options
309
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
310
-
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]
315
- end
316
-
317
- def test_resolves_localhost
318
- assert_nothing_raised do
319
- Redis.new(OPTIONS.merge(:host => 'localhost')).ping
320
- end
321
- end
322
-
323
- class << self
324
- def af_family_supported(af)
325
- hosts = {
326
- Socket::AF_INET => "127.0.0.1",
327
- Socket::AF_INET6 => "::1",
328
- }
329
-
330
- begin
331
- s = Socket.new(af, Socket::SOCK_STREAM, 0)
332
- begin
333
- tries = 5
334
- begin
335
- sa = Socket.pack_sockaddr_in(1024 + Random.rand(63076), hosts[af])
336
- s.bind(sa)
337
- rescue Errno::EADDRINUSE => e
338
- # On JRuby (9.1.15.0), if IPv6 is globally disabled on the system,
339
- # we get an EADDRINUSE with belows message.
340
- if e.message =~ /Protocol family unavailable/
341
- return
342
- end
343
-
344
- tries -= 1
345
- retry if tries > 0
346
-
347
- raise
348
- end
349
- yield
350
- rescue Errno::EADDRNOTAVAIL
351
- ensure
352
- s.close
353
- end
354
- rescue Errno::ESOCKTNOSUPPORT
355
- end
356
- end
357
- end
358
-
359
- def af_test(host)
360
- commands = {
361
- :ping => lambda { |*_| "+pong" },
362
- }
363
-
364
- redis_mock(commands, :host => host) do |redis|
365
- assert_nothing_raised do
366
- redis.ping
367
- end
368
- end
369
- end
370
-
371
- driver(:ruby) do
372
- af_family_supported(Socket::AF_INET) do
373
- def test_connect_ipv4
374
- af_test("127.0.0.1")
375
- end
376
- end
377
- end
378
-
379
- driver(:ruby) do
380
- af_family_supported(Socket::AF_INET6) do
381
- def test_connect_ipv6
382
- af_test("::1")
383
- end
384
- end
385
- end
386
-
387
- def test_can_be_duped_to_create_a_new_connection
388
- clients = r.info["connected_clients"].to_i
389
-
390
- r2 = r.dup
391
- r2.ping
392
-
393
- assert_equal clients + 1, r.info["connected_clients"].to_i
394
- end
395
- 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