redis 4.0.1 → 4.8.1

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 (148) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +220 -0
  3. data/README.md +152 -28
  4. data/lib/redis/client.rb +171 -107
  5. data/lib/redis/cluster/command.rb +79 -0
  6. data/lib/redis/cluster/command_loader.rb +33 -0
  7. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  8. data/lib/redis/cluster/node.rb +120 -0
  9. data/lib/redis/cluster/node_key.rb +31 -0
  10. data/lib/redis/cluster/node_loader.rb +34 -0
  11. data/lib/redis/cluster/option.rb +100 -0
  12. data/lib/redis/cluster/slot.rb +86 -0
  13. data/lib/redis/cluster/slot_loader.rb +46 -0
  14. data/lib/redis/cluster.rb +315 -0
  15. data/lib/redis/commands/bitmaps.rb +63 -0
  16. data/lib/redis/commands/cluster.rb +45 -0
  17. data/lib/redis/commands/connection.rb +58 -0
  18. data/lib/redis/commands/geo.rb +84 -0
  19. data/lib/redis/commands/hashes.rb +251 -0
  20. data/lib/redis/commands/hyper_log_log.rb +37 -0
  21. data/lib/redis/commands/keys.rb +455 -0
  22. data/lib/redis/commands/lists.rb +290 -0
  23. data/lib/redis/commands/pubsub.rb +72 -0
  24. data/lib/redis/commands/scripting.rb +114 -0
  25. data/lib/redis/commands/server.rb +188 -0
  26. data/lib/redis/commands/sets.rb +223 -0
  27. data/lib/redis/commands/sorted_sets.rb +812 -0
  28. data/lib/redis/commands/streams.rb +382 -0
  29. data/lib/redis/commands/strings.rb +313 -0
  30. data/lib/redis/commands/transactions.rb +139 -0
  31. data/lib/redis/commands.rb +240 -0
  32. data/lib/redis/connection/command_helper.rb +5 -2
  33. data/lib/redis/connection/hiredis.rb +7 -5
  34. data/lib/redis/connection/registry.rb +2 -1
  35. data/lib/redis/connection/ruby.rb +139 -111
  36. data/lib/redis/connection/synchrony.rb +17 -10
  37. data/lib/redis/connection.rb +3 -1
  38. data/lib/redis/distributed.rb +244 -87
  39. data/lib/redis/errors.rb +57 -0
  40. data/lib/redis/hash_ring.rb +15 -14
  41. data/lib/redis/pipeline.rb +181 -10
  42. data/lib/redis/subscribe.rb +11 -12
  43. data/lib/redis/version.rb +3 -1
  44. data/lib/redis.rb +180 -2716
  45. metadata +45 -195
  46. data/.gitignore +0 -16
  47. data/.travis/Gemfile +0 -13
  48. data/.travis.yml +0 -73
  49. data/.yardopts +0 -3
  50. data/Gemfile +0 -3
  51. data/benchmarking/logging.rb +0 -71
  52. data/benchmarking/pipeline.rb +0 -51
  53. data/benchmarking/speed.rb +0 -21
  54. data/benchmarking/suite.rb +0 -24
  55. data/benchmarking/worker.rb +0 -71
  56. data/bors.toml +0 -14
  57. data/examples/basic.rb +0 -15
  58. data/examples/consistency.rb +0 -114
  59. data/examples/dist_redis.rb +0 -43
  60. data/examples/incr-decr.rb +0 -17
  61. data/examples/list.rb +0 -26
  62. data/examples/pubsub.rb +0 -37
  63. data/examples/sentinel/sentinel.conf +0 -9
  64. data/examples/sentinel/start +0 -49
  65. data/examples/sentinel.rb +0 -41
  66. data/examples/sets.rb +0 -36
  67. data/examples/unicorn/config.ru +0 -3
  68. data/examples/unicorn/unicorn.rb +0 -20
  69. data/makefile +0 -42
  70. data/redis.gemspec +0 -42
  71. data/test/bitpos_test.rb +0 -63
  72. data/test/blocking_commands_test.rb +0 -40
  73. data/test/client_test.rb +0 -59
  74. data/test/command_map_test.rb +0 -28
  75. data/test/commands_on_hashes_test.rb +0 -19
  76. data/test/commands_on_hyper_log_log_test.rb +0 -19
  77. data/test/commands_on_lists_test.rb +0 -18
  78. data/test/commands_on_sets_test.rb +0 -75
  79. data/test/commands_on_sorted_sets_test.rb +0 -150
  80. data/test/commands_on_strings_test.rb +0 -99
  81. data/test/commands_on_value_types_test.rb +0 -171
  82. data/test/connection_handling_test.rb +0 -275
  83. data/test/connection_test.rb +0 -57
  84. data/test/db/.gitkeep +0 -0
  85. data/test/distributed_blocking_commands_test.rb +0 -44
  86. data/test/distributed_commands_on_hashes_test.rb +0 -8
  87. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -31
  88. data/test/distributed_commands_on_lists_test.rb +0 -20
  89. data/test/distributed_commands_on_sets_test.rb +0 -106
  90. data/test/distributed_commands_on_sorted_sets_test.rb +0 -16
  91. data/test/distributed_commands_on_strings_test.rb +0 -69
  92. data/test/distributed_commands_on_value_types_test.rb +0 -93
  93. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  94. data/test/distributed_connection_handling_test.rb +0 -21
  95. data/test/distributed_internals_test.rb +0 -68
  96. data/test/distributed_key_tags_test.rb +0 -50
  97. data/test/distributed_persistence_control_commands_test.rb +0 -24
  98. data/test/distributed_publish_subscribe_test.rb +0 -90
  99. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  100. data/test/distributed_scripting_test.rb +0 -100
  101. data/test/distributed_sorting_test.rb +0 -18
  102. data/test/distributed_test.rb +0 -56
  103. data/test/distributed_transactions_test.rb +0 -30
  104. data/test/encoding_test.rb +0 -14
  105. data/test/error_replies_test.rb +0 -57
  106. data/test/fork_safety_test.rb +0 -60
  107. data/test/helper.rb +0 -201
  108. data/test/helper_test.rb +0 -22
  109. data/test/internals_test.rb +0 -389
  110. data/test/lint/blocking_commands.rb +0 -150
  111. data/test/lint/hashes.rb +0 -162
  112. data/test/lint/hyper_log_log.rb +0 -60
  113. data/test/lint/lists.rb +0 -143
  114. data/test/lint/sets.rb +0 -140
  115. data/test/lint/sorted_sets.rb +0 -316
  116. data/test/lint/strings.rb +0 -246
  117. data/test/lint/value_types.rb +0 -130
  118. data/test/persistence_control_commands_test.rb +0 -24
  119. data/test/pipelining_commands_test.rb +0 -238
  120. data/test/publish_subscribe_test.rb +0 -280
  121. data/test/remote_server_control_commands_test.rb +0 -175
  122. data/test/scanning_test.rb +0 -407
  123. data/test/scripting_test.rb +0 -76
  124. data/test/sentinel_command_test.rb +0 -78
  125. data/test/sentinel_test.rb +0 -253
  126. data/test/sorting_test.rb +0 -57
  127. data/test/ssl_test.rb +0 -69
  128. data/test/support/connection/hiredis.rb +0 -1
  129. data/test/support/connection/ruby.rb +0 -1
  130. data/test/support/connection/synchrony.rb +0 -17
  131. data/test/support/redis_mock.rb +0 -130
  132. data/test/support/ssl/gen_certs.sh +0 -31
  133. data/test/support/ssl/trusted-ca.crt +0 -25
  134. data/test/support/ssl/trusted-ca.key +0 -27
  135. data/test/support/ssl/trusted-cert.crt +0 -81
  136. data/test/support/ssl/trusted-cert.key +0 -28
  137. data/test/support/ssl/untrusted-ca.crt +0 -26
  138. data/test/support/ssl/untrusted-ca.key +0 -27
  139. data/test/support/ssl/untrusted-cert.crt +0 -82
  140. data/test/support/ssl/untrusted-cert.key +0 -28
  141. data/test/support/wire/synchrony.rb +0 -24
  142. data/test/support/wire/thread.rb +0 -5
  143. data/test/synchrony_driver.rb +0 -85
  144. data/test/test.conf.erb +0 -9
  145. data/test/thread_safety_test.rb +0 -60
  146. data/test/transactions_test.rb +0 -262
  147. data/test/unknown_commands_test.rb +0 -12
  148. data/test/url_param_test.rb +0 -136
@@ -1,389 +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
338
- tries -= 1
339
- retry if tries > 0
340
-
341
- raise
342
- end
343
- yield
344
- rescue Errno::EADDRNOTAVAIL
345
- ensure
346
- s.close
347
- end
348
- rescue Errno::ESOCKTNOSUPPORT
349
- end
350
- end
351
- end
352
-
353
- def af_test(host)
354
- commands = {
355
- :ping => lambda { |*_| "+pong" },
356
- }
357
-
358
- redis_mock(commands, :host => host) do |redis|
359
- assert_nothing_raised do
360
- redis.ping
361
- end
362
- end
363
- end
364
-
365
- driver(:ruby) do
366
- af_family_supported(Socket::AF_INET) do
367
- def test_connect_ipv4
368
- af_test("127.0.0.1")
369
- end
370
- end
371
- end
372
-
373
- driver(:ruby) do
374
- af_family_supported(Socket::AF_INET6) do
375
- def test_connect_ipv6
376
- af_test("::1")
377
- end
378
- end
379
- end
380
-
381
- def test_can_be_duped_to_create_a_new_connection
382
- clients = r.info["connected_clients"].to_i
383
-
384
- r2 = r.dup
385
- r2.ping
386
-
387
- assert_equal clients + 1, r.info["connected_clients"].to_i
388
- end
389
- 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
data/test/lint/hashes.rb DELETED
@@ -1,162 +0,0 @@
1
- module Lint
2
-
3
- module Hashes
4
-
5
- def test_hset_and_hget
6
- r.hset("foo", "f1", "s1")
7
-
8
- assert_equal "s1", r.hget("foo", "f1")
9
- end
10
-
11
- def test_hsetnx
12
- r.hset("foo", "f1", "s1")
13
- r.hsetnx("foo", "f1", "s2")
14
-
15
- assert_equal "s1", r.hget("foo", "f1")
16
-
17
- r.del("foo")
18
- r.hsetnx("foo", "f1", "s2")
19
-
20
- assert_equal "s2", r.hget("foo", "f1")
21
- end
22
-
23
- def test_hdel
24
- r.hset("foo", "f1", "s1")
25
-
26
- assert_equal "s1", r.hget("foo", "f1")
27
-
28
- assert_equal 1, r.hdel("foo", "f1")
29
-
30
- assert_equal nil, r.hget("foo", "f1")
31
- end
32
-
33
- def test_variadic_hdel
34
- target_version "2.3.9" do
35
- r.hset("foo", "f1", "s1")
36
- r.hset("foo", "f2", "s2")
37
-
38
- assert_equal "s1", r.hget("foo", "f1")
39
- assert_equal "s2", r.hget("foo", "f2")
40
-
41
- assert_equal 2, r.hdel("foo", ["f1", "f2"])
42
-
43
- assert_equal nil, r.hget("foo", "f1")
44
- assert_equal nil, r.hget("foo", "f2")
45
- end
46
- end
47
-
48
- def test_hexists
49
- assert_equal false, r.hexists("foo", "f1")
50
-
51
- r.hset("foo", "f1", "s1")
52
-
53
- assert r.hexists("foo", "f1")
54
- end
55
-
56
- def test_hlen
57
- assert_equal 0, r.hlen("foo")
58
-
59
- r.hset("foo", "f1", "s1")
60
-
61
- assert_equal 1, r.hlen("foo")
62
-
63
- r.hset("foo", "f2", "s2")
64
-
65
- assert_equal 2, r.hlen("foo")
66
- end
67
-
68
- def test_hkeys
69
- assert_equal [], r.hkeys("foo")
70
-
71
- r.hset("foo", "f1", "s1")
72
- r.hset("foo", "f2", "s2")
73
-
74
- assert_equal ["f1", "f2"], r.hkeys("foo")
75
- end
76
-
77
- def test_hvals
78
- assert_equal [], r.hvals("foo")
79
-
80
- r.hset("foo", "f1", "s1")
81
- r.hset("foo", "f2", "s2")
82
-
83
- assert_equal ["s1", "s2"], r.hvals("foo")
84
- end
85
-
86
- def test_hgetall
87
- assert({} == r.hgetall("foo"))
88
-
89
- r.hset("foo", "f1", "s1")
90
- r.hset("foo", "f2", "s2")
91
-
92
- assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
93
- end
94
-
95
- def test_hmset
96
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
97
-
98
- assert_equal "bar1", r.hget("hash", "foo1")
99
- assert_equal "bar2", r.hget("hash", "foo2")
100
- end
101
-
102
- def test_hmset_with_invalid_arguments
103
- assert_raise(Redis::CommandError) do
104
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
105
- end
106
- end
107
-
108
- def test_mapped_hmset
109
- r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
110
-
111
- assert_equal "s1", r.hget("foo", "f1")
112
- assert_equal "s2", r.hget("foo", "f2")
113
- end
114
-
115
- def test_hmget
116
- r.hset("foo", "f1", "s1")
117
- r.hset("foo", "f2", "s2")
118
- r.hset("foo", "f3", "s3")
119
-
120
- assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
121
- end
122
-
123
- def test_hmget_mapped
124
- r.hset("foo", "f1", "s1")
125
- r.hset("foo", "f2", "s2")
126
- r.hset("foo", "f3", "s3")
127
-
128
- assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
129
- assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
130
- end
131
-
132
- def test_hincrby
133
- r.hincrby("foo", "f1", 1)
134
-
135
- assert_equal "1", r.hget("foo", "f1")
136
-
137
- r.hincrby("foo", "f1", 2)
138
-
139
- assert_equal "3", r.hget("foo", "f1")
140
-
141
- r.hincrby("foo", "f1", -1)
142
-
143
- assert_equal "2", r.hget("foo", "f1")
144
- end
145
-
146
- def test_hincrbyfloat
147
- target_version "2.5.4" do
148
- r.hincrbyfloat("foo", "f1", 1.23)
149
-
150
- assert_equal "1.23", r.hget("foo", "f1")
151
-
152
- r.hincrbyfloat("foo", "f1", 0.77)
153
-
154
- assert_equal "2", r.hget("foo", "f1")
155
-
156
- r.hincrbyfloat("foo", "f1", -0.1)
157
-
158
- assert_equal "1.9", r.hget("foo", "f1")
159
- end
160
- end
161
- end
162
- end