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