redis 4.0.0.rc1 → 4.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +164 -3
- data/README.md +127 -18
- data/lib/redis/client.rb +164 -93
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +108 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +37 -0
- data/lib/redis/cluster/option.rb +93 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +49 -0
- data/lib/redis/cluster.rb +291 -0
- data/lib/redis/connection/command_helper.rb +5 -2
- data/lib/redis/connection/hiredis.rb +4 -3
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +125 -106
- data/lib/redis/connection/synchrony.rb +18 -5
- data/lib/redis/connection.rb +2 -0
- data/lib/redis/distributed.rb +995 -0
- data/lib/redis/errors.rb +48 -0
- data/lib/redis/hash_ring.rb +89 -0
- data/lib/redis/pipeline.rb +55 -9
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +1433 -381
- metadata +34 -141
- data/.gitignore +0 -16
- data/.travis/Gemfile +0 -11
- data/.travis.yml +0 -71
- data/.yardopts +0 -3
- data/Gemfile +0 -3
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sentinel.rb +0 -41
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/makefile +0 -42
- data/redis.gemspec +0 -40
- data/test/bitpos_test.rb +0 -63
- data/test/blocking_commands_test.rb +0 -183
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -28
- data/test/commands_on_hashes_test.rb +0 -174
- data/test/commands_on_hyper_log_log_test.rb +0 -70
- data/test/commands_on_lists_test.rb +0 -154
- data/test/commands_on_sets_test.rb +0 -208
- data/test/commands_on_sorted_sets_test.rb +0 -444
- data/test/commands_on_strings_test.rb +0 -338
- data/test/commands_on_value_types_test.rb +0 -246
- data/test/connection_handling_test.rb +0 -275
- data/test/db/.gitkeep +0 -0
- data/test/encoding_test.rb +0 -14
- data/test/error_replies_test.rb +0 -57
- data/test/fork_safety_test.rb +0 -60
- data/test/helper.rb +0 -179
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -435
- data/test/persistence_control_commands_test.rb +0 -24
- data/test/pipelining_commands_test.rb +0 -238
- data/test/publish_subscribe_test.rb +0 -280
- data/test/remote_server_control_commands_test.rb +0 -175
- data/test/scanning_test.rb +0 -407
- data/test/scripting_test.rb +0 -76
- data/test/sentinel_command_test.rb +0 -78
- data/test/sentinel_test.rb +0 -253
- data/test/sorting_test.rb +0 -57
- data/test/ssl_test.rb +0 -69
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -85
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -60
- data/test/transactions_test.rb +0 -262
- data/test/unknown_commands_test.rb +0 -12
- data/test/url_param_test.rb +0 -136
data/test/internals_test.rb
DELETED
@@ -1,435 +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 close_on_ping(seq, options = {})
|
162
|
-
$request = 0
|
163
|
-
|
164
|
-
command = lambda do
|
165
|
-
idx = $request
|
166
|
-
$request += 1
|
167
|
-
|
168
|
-
rv = "+%d" % idx
|
169
|
-
rv = nil if seq.include?(idx)
|
170
|
-
rv
|
171
|
-
end
|
172
|
-
|
173
|
-
redis_mock({:ping => command}, {:timeout => 0.1}.merge(options)) do |redis|
|
174
|
-
yield(redis)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_retry_by_default
|
179
|
-
close_on_ping([0]) do |redis|
|
180
|
-
assert_equal "1", redis.ping
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_retry_when_wrapped_in_with_reconnect_true
|
185
|
-
close_on_ping([0]) do |redis|
|
186
|
-
redis.with_reconnect(true) do
|
187
|
-
assert_equal "1", redis.ping
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_dont_retry_when_wrapped_in_with_reconnect_false
|
193
|
-
close_on_ping([0]) do |redis|
|
194
|
-
assert_raise Redis::ConnectionError do
|
195
|
-
redis.with_reconnect(false) do
|
196
|
-
redis.ping
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_dont_retry_when_wrapped_in_without_reconnect
|
203
|
-
close_on_ping([0]) do |redis|
|
204
|
-
assert_raise Redis::ConnectionError do
|
205
|
-
redis.without_reconnect do
|
206
|
-
redis.ping
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_retry_only_once_when_read_raises_econnreset
|
213
|
-
close_on_ping([0, 1]) do |redis|
|
214
|
-
assert_raise Redis::ConnectionError do
|
215
|
-
redis.ping
|
216
|
-
end
|
217
|
-
|
218
|
-
assert !redis._client.connected?
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_retry_with_custom_reconnect_attempts
|
223
|
-
close_on_ping([0, 1], :reconnect_attempts => 2) do |redis|
|
224
|
-
assert_equal "2", redis.ping
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_retry_with_custom_reconnect_attempts_can_still_fail
|
229
|
-
close_on_ping([0, 1, 2], :reconnect_attempts => 2) do |redis|
|
230
|
-
assert_raise Redis::ConnectionError do
|
231
|
-
redis.ping
|
232
|
-
end
|
233
|
-
|
234
|
-
assert !redis._client.connected?
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_don_t_retry_when_second_read_in_pipeline_raises_econnreset
|
239
|
-
close_on_ping([1]) do |redis|
|
240
|
-
assert_raise Redis::ConnectionError do
|
241
|
-
redis.pipelined do
|
242
|
-
redis.ping
|
243
|
-
redis.ping # Second #read times out
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
assert !redis._client.connected?
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
def close_on_connection(seq)
|
252
|
-
$n = 0
|
253
|
-
|
254
|
-
read_command = lambda do |session|
|
255
|
-
Array.new(session.gets[1..-3].to_i) do
|
256
|
-
bytes = session.gets[1..-3].to_i
|
257
|
-
arg = session.read(bytes)
|
258
|
-
session.read(2) # Discard \r\n
|
259
|
-
arg
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
handler = lambda do |session|
|
264
|
-
n = $n
|
265
|
-
$n += 1
|
266
|
-
|
267
|
-
select = read_command.call(session)
|
268
|
-
if select[0].downcase == "select"
|
269
|
-
session.write("+OK\r\n")
|
270
|
-
else
|
271
|
-
raise "Expected SELECT"
|
272
|
-
end
|
273
|
-
|
274
|
-
if !seq.include?(n)
|
275
|
-
while read_command.call(session)
|
276
|
-
session.write("+#{n}\r\n")
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
redis_mock_with_handler(handler) do |redis|
|
282
|
-
yield(redis)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_retry_on_write_error_by_default
|
287
|
-
close_on_connection([0]) do |redis|
|
288
|
-
assert_equal "1", redis._client.call(["x" * 128 * 1024])
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
|
293
|
-
close_on_connection([0]) do |redis|
|
294
|
-
redis.with_reconnect(true) do
|
295
|
-
assert_equal "1", redis._client.call(["x" * 128 * 1024])
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_dont_retry_on_write_error_when_wrapped_in_with_reconnect_false
|
301
|
-
close_on_connection([0]) do |redis|
|
302
|
-
assert_raise Redis::ConnectionError do
|
303
|
-
redis.with_reconnect(false) do
|
304
|
-
redis._client.call(["x" * 128 * 1024])
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def test_dont_retry_on_write_error_when_wrapped_in_without_reconnect
|
311
|
-
close_on_connection([0]) do |redis|
|
312
|
-
assert_raise Redis::ConnectionError do
|
313
|
-
redis.without_reconnect do
|
314
|
-
redis._client.call(["x" * 128 * 1024])
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_connecting_to_unix_domain_socket
|
321
|
-
assert_nothing_raised do
|
322
|
-
Redis.new(OPTIONS.merge(:path => ENV.fetch("SOCKET_PATH"))).ping
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
driver(:ruby, :hiredis) do
|
327
|
-
def test_bubble_timeout_without_retrying
|
328
|
-
serv = TCPServer.new(6380)
|
329
|
-
|
330
|
-
redis = Redis.new(:port => 6380, :timeout => 0.1)
|
331
|
-
|
332
|
-
assert_raise(Redis::TimeoutError) do
|
333
|
-
redis.ping
|
334
|
-
end
|
335
|
-
|
336
|
-
ensure
|
337
|
-
serv.close if serv
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_client_options
|
342
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
|
343
|
-
|
344
|
-
assert_equal "host", redis._client.options[:host]
|
345
|
-
assert_equal 1234, redis._client.options[:port]
|
346
|
-
assert_equal 1, redis._client.options[:db]
|
347
|
-
assert_equal "foo", redis._client.options[:scheme]
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_does_not_change_self_client_options
|
351
|
-
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
|
352
|
-
options = redis._client.options
|
353
|
-
|
354
|
-
options[:host] << "new_host"
|
355
|
-
options[:scheme] << "bar"
|
356
|
-
options.merge!(:db => 0)
|
357
|
-
|
358
|
-
assert_equal "host", redis._client.options[:host]
|
359
|
-
assert_equal 1, redis._client.options[:db]
|
360
|
-
assert_equal "foo", redis._client.options[:scheme]
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_resolves_localhost
|
364
|
-
assert_nothing_raised do
|
365
|
-
Redis.new(OPTIONS.merge(:host => 'localhost')).ping
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
class << self
|
370
|
-
def af_family_supported(af)
|
371
|
-
hosts = {
|
372
|
-
Socket::AF_INET => "127.0.0.1",
|
373
|
-
Socket::AF_INET6 => "::1",
|
374
|
-
}
|
375
|
-
|
376
|
-
begin
|
377
|
-
s = Socket.new(af, Socket::SOCK_STREAM, 0)
|
378
|
-
begin
|
379
|
-
tries = 5
|
380
|
-
begin
|
381
|
-
sa = Socket.pack_sockaddr_in(1024 + Random.rand(63076), hosts[af])
|
382
|
-
s.bind(sa)
|
383
|
-
rescue Errno::EADDRINUSE
|
384
|
-
tries -= 1
|
385
|
-
retry if tries > 0
|
386
|
-
|
387
|
-
raise
|
388
|
-
end
|
389
|
-
yield
|
390
|
-
rescue Errno::EADDRNOTAVAIL
|
391
|
-
ensure
|
392
|
-
s.close
|
393
|
-
end
|
394
|
-
rescue Errno::ESOCKTNOSUPPORT
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
def af_test(host)
|
400
|
-
commands = {
|
401
|
-
:ping => lambda { |*_| "+pong" },
|
402
|
-
}
|
403
|
-
|
404
|
-
redis_mock(commands, :host => host) do |redis|
|
405
|
-
assert_nothing_raised do
|
406
|
-
redis.ping
|
407
|
-
end
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
driver(:ruby) do
|
412
|
-
af_family_supported(Socket::AF_INET) do
|
413
|
-
def test_connect_ipv4
|
414
|
-
af_test("127.0.0.1")
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
driver(:ruby) do
|
420
|
-
af_family_supported(Socket::AF_INET6) do
|
421
|
-
def test_connect_ipv6
|
422
|
-
af_test("::1")
|
423
|
-
end
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
def test_can_be_duped_to_create_a_new_connection
|
428
|
-
clients = r.info["connected_clients"].to_i
|
429
|
-
|
430
|
-
r2 = r.dup
|
431
|
-
r2.ping
|
432
|
-
|
433
|
-
assert_equal clients + 1, r.info["connected_clients"].to_i
|
434
|
-
end
|
435
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestPersistenceControlCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_save
|
8
|
-
redis_mock(:save => lambda { "+SAVE" }) do |redis|
|
9
|
-
assert_equal "SAVE", redis.save
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_bgsave
|
14
|
-
redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
|
15
|
-
assert_equal "BGSAVE", redis.bgsave
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_lastsave
|
20
|
-
redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
|
21
|
-
assert_equal "LASTSAVE", redis.lastsave
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,238 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestPipeliningCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_bulk_commands
|
8
|
-
r.pipelined do
|
9
|
-
r.lpush "foo", "s1"
|
10
|
-
r.lpush "foo", "s2"
|
11
|
-
end
|
12
|
-
|
13
|
-
assert_equal 2, r.llen("foo")
|
14
|
-
assert_equal "s2", r.lpop("foo")
|
15
|
-
assert_equal "s1", r.lpop("foo")
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_multi_bulk_commands
|
19
|
-
r.pipelined do
|
20
|
-
r.mset("foo", "s1", "bar", "s2")
|
21
|
-
r.mset("baz", "s3", "qux", "s4")
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal "s1", r.get("foo")
|
25
|
-
assert_equal "s2", r.get("bar")
|
26
|
-
assert_equal "s3", r.get("baz")
|
27
|
-
assert_equal "s4", r.get("qux")
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_bulk_and_multi_bulk_commands_mixed
|
31
|
-
r.pipelined do
|
32
|
-
r.lpush "foo", "s1"
|
33
|
-
r.lpush "foo", "s2"
|
34
|
-
r.mset("baz", "s3", "qux", "s4")
|
35
|
-
end
|
36
|
-
|
37
|
-
assert_equal 2, r.llen("foo")
|
38
|
-
assert_equal "s2", r.lpop("foo")
|
39
|
-
assert_equal "s1", r.lpop("foo")
|
40
|
-
assert_equal "s3", r.get("baz")
|
41
|
-
assert_equal "s4", r.get("qux")
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_multi_bulk_and_bulk_commands_mixed
|
45
|
-
r.pipelined do
|
46
|
-
r.mset("baz", "s3", "qux", "s4")
|
47
|
-
r.lpush "foo", "s1"
|
48
|
-
r.lpush "foo", "s2"
|
49
|
-
end
|
50
|
-
|
51
|
-
assert_equal 2, r.llen("foo")
|
52
|
-
assert_equal "s2", r.lpop("foo")
|
53
|
-
assert_equal "s1", r.lpop("foo")
|
54
|
-
assert_equal "s3", r.get("baz")
|
55
|
-
assert_equal "s4", r.get("qux")
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_pipelined_with_an_empty_block
|
59
|
-
assert_nothing_raised do
|
60
|
-
r.pipelined do
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_equal 0, r.dbsize
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_returning_the_result_of_a_pipeline
|
68
|
-
result = r.pipelined do
|
69
|
-
r.set "foo", "bar"
|
70
|
-
r.get "foo"
|
71
|
-
r.get "bar"
|
72
|
-
end
|
73
|
-
|
74
|
-
assert_equal ["OK", "bar", nil], result
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_assignment_of_results_inside_the_block
|
78
|
-
r.pipelined do
|
79
|
-
@first = r.sadd("foo", 1)
|
80
|
-
@second = r.sadd("foo", 1)
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_equal true, @first.value
|
84
|
-
assert_equal false, @second.value
|
85
|
-
end
|
86
|
-
|
87
|
-
# Although we could support accessing the values in these futures,
|
88
|
-
# it doesn't make a lot of sense.
|
89
|
-
def test_assignment_of_results_inside_the_block_with_errors
|
90
|
-
assert_raise(Redis::CommandError) do
|
91
|
-
r.pipelined do
|
92
|
-
r.doesnt_exist
|
93
|
-
@first = r.sadd("foo", 1)
|
94
|
-
@second = r.sadd("foo", 1)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
assert_raise(Redis::FutureNotReady) { @first.value }
|
99
|
-
assert_raise(Redis::FutureNotReady) { @second.value }
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_assignment_of_results_inside_a_nested_block
|
103
|
-
r.pipelined do
|
104
|
-
@first = r.sadd("foo", 1)
|
105
|
-
|
106
|
-
r.pipelined do
|
107
|
-
@second = r.sadd("foo", 1)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
assert_equal true, @first.value
|
112
|
-
assert_equal false, @second.value
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_futures_raise_when_confused_with_something_else
|
116
|
-
r.pipelined do
|
117
|
-
@result = r.sadd("foo", 1)
|
118
|
-
end
|
119
|
-
|
120
|
-
assert_raise(NoMethodError) { @result.to_s }
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_futures_raise_when_trying_to_access_their_values_too_early
|
124
|
-
r.pipelined do
|
125
|
-
assert_raise(Redis::FutureNotReady) do
|
126
|
-
r.sadd("foo", 1).value
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_futures_can_be_identified
|
132
|
-
r.pipelined do
|
133
|
-
@result = r.sadd("foo", 1)
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_equal true, @result.is_a?(Redis::Future)
|
137
|
-
assert_equal true, @result.is_a?(::BasicObject)
|
138
|
-
assert_equal Redis::Future, @result.class
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_returning_the_result_of_an_empty_pipeline
|
142
|
-
result = r.pipelined do
|
143
|
-
end
|
144
|
-
|
145
|
-
assert_equal [], result
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_nesting_pipeline_blocks
|
149
|
-
r.pipelined do
|
150
|
-
r.set("foo", "s1")
|
151
|
-
r.pipelined do
|
152
|
-
r.set("bar", "s2")
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
assert_equal "s1", r.get("foo")
|
157
|
-
assert_equal "s2", r.get("bar")
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_info_in_a_pipeline_returns_hash
|
161
|
-
result = r.pipelined do
|
162
|
-
r.info
|
163
|
-
end
|
164
|
-
|
165
|
-
assert result.first.kind_of?(Hash)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_config_get_in_a_pipeline_returns_hash
|
169
|
-
result = r.pipelined do
|
170
|
-
r.config(:get, "*")
|
171
|
-
end
|
172
|
-
|
173
|
-
assert result.first.kind_of?(Hash)
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_hgetall_in_a_pipeline_returns_hash
|
177
|
-
r.hmset("hash", "field", "value")
|
178
|
-
result = r.pipelined do
|
179
|
-
r.hgetall("hash")
|
180
|
-
end
|
181
|
-
|
182
|
-
assert_equal result.first, { "field" => "value" }
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_keys_in_a_pipeline
|
186
|
-
r.set("key", "value")
|
187
|
-
result = r.pipelined do
|
188
|
-
r.keys("*")
|
189
|
-
end
|
190
|
-
|
191
|
-
assert_equal ["key"], result.first
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_pipeline_yields_a_connection
|
195
|
-
r.pipelined do |p|
|
196
|
-
p.set("foo", "bar")
|
197
|
-
end
|
198
|
-
|
199
|
-
assert_equal "bar", r.get("foo")
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_pipeline_select
|
203
|
-
r.select 1
|
204
|
-
r.set("db", "1")
|
205
|
-
|
206
|
-
r.pipelined do |p|
|
207
|
-
p.select 2
|
208
|
-
p.set("db", "2")
|
209
|
-
end
|
210
|
-
|
211
|
-
r.select 1
|
212
|
-
assert_equal "1", r.get("db")
|
213
|
-
|
214
|
-
r.select 2
|
215
|
-
assert_equal "2", r.get("db")
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_pipeline_select_client_db
|
219
|
-
r.select 1
|
220
|
-
r.pipelined do |p2|
|
221
|
-
p2.select 2
|
222
|
-
end
|
223
|
-
|
224
|
-
assert_equal 2, r._client.db
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_nested_pipeline_select_client_db
|
228
|
-
r.select 1
|
229
|
-
r.pipelined do |p2|
|
230
|
-
p2.select 2
|
231
|
-
p2.pipelined do |p3|
|
232
|
-
p3.select 3
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
assert_equal 3, r._client.db
|
237
|
-
end
|
238
|
-
end
|