redis 3.3.5 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +32 -50
- data/CHANGELOG.md +7 -9
- data/Gemfile +0 -1
- data/README.md +31 -75
- data/benchmarking/logging.rb +1 -1
- data/lib/redis.rb +31 -35
- data/lib/redis/client.rb +13 -8
- data/lib/redis/connection.rb +2 -2
- data/lib/redis/connection/command_helper.rb +2 -8
- data/lib/redis/connection/hiredis.rb +2 -2
- data/lib/redis/connection/ruby.rb +7 -27
- data/lib/redis/connection/synchrony.rb +3 -3
- data/lib/redis/pipeline.rb +0 -6
- data/lib/redis/version.rb +1 -1
- data/makefile +42 -0
- data/redis.gemspec +4 -8
- data/test/bitpos_test.rb +13 -19
- data/test/blocking_commands_test.rb +147 -6
- data/test/client_test.rb +1 -1
- data/test/command_map_test.rb +3 -5
- data/test/commands_on_hashes_test.rb +158 -5
- data/test/commands_on_hyper_log_log_test.rb +55 -6
- data/test/commands_on_lists_test.rb +139 -5
- data/test/commands_on_sets_test.rb +136 -5
- data/test/commands_on_sorted_sets_test.rb +312 -5
- data/test/commands_on_strings_test.rb +243 -6
- data/test/commands_on_value_types_test.rb +120 -7
- data/test/connection_handling_test.rb +5 -7
- data/test/encoding_test.rb +4 -8
- data/test/error_replies_test.rb +2 -4
- data/test/fork_safety_test.rb +1 -6
- data/test/helper.rb +9 -62
- data/test/helper_test.rb +1 -3
- data/test/internals_test.rb +67 -49
- data/test/persistence_control_commands_test.rb +1 -3
- data/test/pipelining_commands_test.rb +4 -8
- data/test/publish_subscribe_test.rb +1 -3
- data/test/remote_server_control_commands_test.rb +61 -4
- data/test/scanning_test.rb +1 -7
- data/test/scripting_test.rb +1 -3
- data/test/sentinel_command_test.rb +1 -3
- data/test/sentinel_test.rb +1 -3
- data/test/sorting_test.rb +1 -3
- data/test/ssl_test.rb +45 -49
- data/test/support/connection/hiredis.rb +1 -1
- data/test/support/connection/ruby.rb +1 -1
- data/test/support/connection/synchrony.rb +1 -1
- data/test/synchrony_driver.rb +6 -9
- data/test/thread_safety_test.rb +1 -3
- data/test/transactions_test.rb +1 -3
- data/test/unknown_commands_test.rb +1 -3
- data/test/url_param_test.rb +44 -46
- metadata +31 -77
- data/Rakefile +0 -87
- data/examples/dist_redis.rb +0 -43
- data/lib/redis/distributed.rb +0 -873
- data/lib/redis/hash_ring.rb +0 -132
- data/test/connection_test.rb +0 -57
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -59
- data/test/distributed_commands_on_value_types_test.rb +0 -95
- data/test/distributed_commands_requiring_clustering_test.rb +0 -164
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -79
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -66
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -260
- data/test/lint/value_types.rb +0 -122
data/lib/redis/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "errors"
|
2
2
|
require "socket"
|
3
3
|
require "cgi"
|
4
4
|
|
@@ -451,12 +451,12 @@ class Redis
|
|
451
451
|
case options[:tcp_keepalive]
|
452
452
|
when Hash
|
453
453
|
[:time, :intvl, :probes].each do |key|
|
454
|
-
unless options[:tcp_keepalive][key].is_a?(
|
455
|
-
raise "Expected the #{key.inspect} key in :tcp_keepalive to be
|
454
|
+
unless options[:tcp_keepalive][key].is_a?(Fixnum)
|
455
|
+
raise "Expected the #{key.inspect} key in :tcp_keepalive to be a Fixnum"
|
456
456
|
end
|
457
457
|
end
|
458
458
|
|
459
|
-
when
|
459
|
+
when Fixnum
|
460
460
|
if options[:tcp_keepalive] >= 60
|
461
461
|
options[:tcp_keepalive] = {:time => options[:tcp_keepalive] - 20, :intvl => 10, :probes => 2}
|
462
462
|
|
@@ -478,11 +478,16 @@ class Redis
|
|
478
478
|
|
479
479
|
if driver.kind_of?(String)
|
480
480
|
begin
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
481
|
+
require_relative "connection/#{driver}"
|
482
|
+
rescue LoadError, NameError => e
|
483
|
+
begin
|
484
|
+
require "connection/#{driver}"
|
485
|
+
rescue LoadError, NameError => e
|
486
|
+
raise RuntimeError, "Cannot load driver #{driver.inspect}: #{e.message}"
|
487
|
+
end
|
485
488
|
end
|
489
|
+
|
490
|
+
driver = Connection.const_get(driver.capitalize)
|
486
491
|
end
|
487
492
|
|
488
493
|
driver
|
data/lib/redis/connection.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "connection/registry"
|
2
2
|
|
3
3
|
# If a connection driver was required before this file, the array
|
4
4
|
# Redis::Connection.drivers will contain one or more classes. The last driver
|
@@ -6,4 +6,4 @@ require "redis/connection/registry"
|
|
6
6
|
# the plain Ruby driver as our default. Another driver can be required at a
|
7
7
|
# later point in time, causing it to be the last element of the #drivers array
|
8
8
|
# and therefore be chosen by default.
|
9
|
-
|
9
|
+
require_relative "connection/ruby" if Redis::Connection.drivers.empty?
|
@@ -30,14 +30,8 @@ class Redis
|
|
30
30
|
|
31
31
|
protected
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
string.force_encoding(Encoding::default_external)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
def encode(string)
|
39
|
-
string
|
40
|
-
end
|
33
|
+
def encode(string)
|
34
|
+
string.force_encoding(Encoding.default_external)
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative "registry"
|
2
|
+
require_relative "command_helper"
|
3
|
+
require_relative "../errors"
|
4
4
|
require "socket"
|
5
5
|
require "timeout"
|
6
6
|
|
@@ -10,31 +10,12 @@ rescue LoadError
|
|
10
10
|
# Not all systems have OpenSSL support
|
11
11
|
end
|
12
12
|
|
13
|
-
if RUBY_VERSION < "1.9.3"
|
14
|
-
class String
|
15
|
-
# Ruby 1.8.7 does not have byteslice, but it handles encodings differently anyway.
|
16
|
-
# We can simply slice the string, which is a byte array there.
|
17
|
-
def byteslice(*args)
|
18
|
-
slice(*args)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
13
|
class Redis
|
24
14
|
module Connection
|
25
15
|
module SocketMixin
|
26
16
|
|
27
17
|
CRLF = "\r\n".freeze
|
28
18
|
|
29
|
-
# Exceptions raised during non-blocking I/O ops that require retrying the op
|
30
|
-
if RUBY_VERSION >= "1.9.3"
|
31
|
-
NBIO_READ_EXCEPTIONS = [IO::WaitReadable]
|
32
|
-
NBIO_WRITE_EXCEPTIONS = [IO::WaitWritable]
|
33
|
-
else
|
34
|
-
NBIO_READ_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
|
35
|
-
NBIO_WRITE_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
|
36
|
-
end
|
37
|
-
|
38
19
|
def initialize(*args)
|
39
20
|
super(*args)
|
40
21
|
|
@@ -83,13 +64,13 @@ class Redis
|
|
83
64
|
begin
|
84
65
|
read_nonblock(nbytes)
|
85
66
|
|
86
|
-
rescue
|
67
|
+
rescue IO::WaitReadable
|
87
68
|
if IO.select([self], nil, nil, @timeout)
|
88
69
|
retry
|
89
70
|
else
|
90
71
|
raise Redis::TimeoutError
|
91
72
|
end
|
92
|
-
rescue
|
73
|
+
rescue IO::WaitWritable
|
93
74
|
if IO.select(nil, [self], nil, @timeout)
|
94
75
|
retry
|
95
76
|
else
|
@@ -105,13 +86,13 @@ class Redis
|
|
105
86
|
begin
|
106
87
|
write_nonblock(data)
|
107
88
|
|
108
|
-
rescue
|
89
|
+
rescue IO::WaitWritable
|
109
90
|
if IO.select(nil, [self], nil, @write_timeout)
|
110
91
|
retry
|
111
92
|
else
|
112
93
|
raise Redis::TimeoutError
|
113
94
|
end
|
114
|
-
rescue
|
95
|
+
rescue IO::WaitReadable
|
115
96
|
if IO.select([self], nil, nil, @write_timeout)
|
116
97
|
retry
|
117
98
|
else
|
@@ -307,7 +288,6 @@ class Redis
|
|
307
288
|
raise ArgumentError, "SSL incompatible with unix sockets" if config[:ssl]
|
308
289
|
sock = UNIXSocket.connect(config[:path], config[:connect_timeout])
|
309
290
|
elsif config[:scheme] == "rediss" || config[:ssl]
|
310
|
-
raise ArgumentError, "This library does not support SSL on Ruby < 1.9" if RUBY_VERSION < "1.9.3"
|
311
291
|
sock = SSLSocket.connect(config[:host], config[:port], config[:connect_timeout], config[:ssl_params])
|
312
292
|
else
|
313
293
|
sock = TCPSocket.connect(config[:host], config[:port], config[:connect_timeout])
|
data/lib/redis/pipeline.rb
CHANGED
data/lib/redis/version.rb
CHANGED
data/makefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
TEST_FILES := $(shell find test -name *_test.rb -type f)
|
2
|
+
REDIS_BRANCH := unstable
|
3
|
+
TMP := tmp
|
4
|
+
BUILD_DIR := ${TMP}/redis-${REDIS_BRANCH}
|
5
|
+
TARBALL := ${TMP}/redis-${REDIS_BRANCH}.tar.gz
|
6
|
+
BINARY := ${BUILD_DIR}/src/redis-server
|
7
|
+
PID_PATH := ${BUILD_DIR}/redis.pid
|
8
|
+
SOCKET_PATH := ${BUILD_DIR}/redis.sock
|
9
|
+
PORT := 6381
|
10
|
+
|
11
|
+
test: ${TEST_FILES}
|
12
|
+
make start
|
13
|
+
env SOCKET_PATH=${SOCKET_PATH} \
|
14
|
+
ruby -v $$(echo $? | tr ' ' '\n' | awk '{ print "-r./" $$0 }') -e ''
|
15
|
+
make stop
|
16
|
+
|
17
|
+
${TMP}:
|
18
|
+
mkdir $@
|
19
|
+
|
20
|
+
${TARBALL}: ${TMP}
|
21
|
+
wget https://github.com/antirez/redis/archive/${REDIS_BRANCH}.tar.gz -O $@
|
22
|
+
|
23
|
+
${BINARY}: ${TARBALL} ${TMP}
|
24
|
+
rm -rf ${BUILD_DIR}
|
25
|
+
mkdir -p ${BUILD_DIR}
|
26
|
+
tar xf ${TARBALL} -C ${TMP}
|
27
|
+
cd ${BUILD_DIR} && make
|
28
|
+
|
29
|
+
stop:
|
30
|
+
(test -f ${PID_PATH} && (kill $$(cat ${PID_PATH}) || true) && rm -f ${PID_PATH}) || true
|
31
|
+
|
32
|
+
start: ${BINARY}
|
33
|
+
${BINARY} \
|
34
|
+
--daemonize yes \
|
35
|
+
--pidfile ${PID_PATH} \
|
36
|
+
--port ${PORT} \
|
37
|
+
--unixsocket ${SOCKET_PATH}
|
38
|
+
|
39
|
+
clean:
|
40
|
+
(test -d ${BUILD_DIR} && cd ${BUILD_DIR}/src && make clean distclean) || true
|
41
|
+
|
42
|
+
.PHONY: test start stop
|
data/redis.gemspec
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$:.unshift File.expand_path("../lib", __FILE__)
|
4
|
-
|
5
|
-
require "redis/version"
|
1
|
+
require "./lib/redis/version"
|
6
2
|
|
7
3
|
Gem::Specification.new do |s|
|
8
4
|
s.name = "redis"
|
@@ -15,8 +11,7 @@ Gem::Specification.new do |s|
|
|
15
11
|
|
16
12
|
s.description = <<-EOS
|
17
13
|
A Ruby client that tries to match Redis' API one-to-one, while still
|
18
|
-
providing an idiomatic interface.
|
19
|
-
client-side sharding, pipelining, and an obsession for performance.
|
14
|
+
providing an idiomatic interface.
|
20
15
|
EOS
|
21
16
|
|
22
17
|
s.license = "MIT"
|
@@ -39,6 +34,7 @@ Gem::Specification.new do |s|
|
|
39
34
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
40
35
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
41
36
|
|
42
|
-
s.add_development_dependency("rake", "<11.0.0")
|
43
37
|
s.add_development_dependency("test-unit", "3.1.5")
|
38
|
+
s.add_development_dependency("hiredis")
|
39
|
+
s.add_development_dependency("em-synchrony")
|
44
40
|
end
|
data/test/bitpos_test.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
unless defined?(Enumerator)
|
6
|
-
Enumerator = Enumerable::Enumerator
|
7
|
-
end
|
1
|
+
require_relative "helper"
|
8
2
|
|
9
3
|
class TestBitpos < Test::Unit::TestCase
|
10
4
|
|
@@ -13,48 +7,48 @@ class TestBitpos < Test::Unit::TestCase
|
|
13
7
|
def test_bitpos_empty_zero
|
14
8
|
target_version "2.9.11" do
|
15
9
|
r.del "foo"
|
16
|
-
assert_equal
|
10
|
+
assert_equal(0, r.bitpos("foo", 0))
|
17
11
|
end
|
18
12
|
end
|
19
13
|
|
20
14
|
def test_bitpos_empty_one
|
21
15
|
target_version "2.9.11" do
|
22
16
|
r.del "foo"
|
23
|
-
assert_equal
|
17
|
+
assert_equal(-1, r.bitpos("foo", 1))
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
27
21
|
def test_bitpos_zero
|
28
22
|
target_version "2.9.11" do
|
29
23
|
r.set "foo", "\xff\xf0\x00"
|
30
|
-
assert_equal
|
24
|
+
assert_equal(12, r.bitpos("foo", 0))
|
31
25
|
end
|
32
26
|
end
|
33
27
|
|
34
28
|
def test_bitpos_one
|
35
29
|
target_version "2.9.11" do
|
36
30
|
r.set "foo", "\x00\x0f\x00"
|
37
|
-
assert_equal
|
31
|
+
assert_equal(12, r.bitpos("foo", 1))
|
38
32
|
end
|
39
33
|
end
|
40
34
|
|
41
35
|
def test_bitpos_zero_end_is_given
|
42
36
|
target_version "2.9.11" do
|
43
37
|
r.set "foo", "\xff\xff\xff"
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
46
|
-
assert_equal
|
38
|
+
assert_equal(24, r.bitpos("foo", 0))
|
39
|
+
assert_equal(24, r.bitpos("foo", 0, 0))
|
40
|
+
assert_equal(-1, r.bitpos("foo", 0, 0, -1))
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
50
44
|
def test_bitpos_one_intervals
|
51
45
|
target_version "2.9.11" do
|
52
46
|
r.set "foo", "\x00\xff\x00"
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
47
|
+
assert_equal(8, r.bitpos("foo", 1, 0, -1))
|
48
|
+
assert_equal(8, r.bitpos("foo", 1, 1, -1))
|
49
|
+
assert_equal(-1, r.bitpos("foo", 1, 2, -1))
|
50
|
+
assert_equal(-1, r.bitpos("foo", 1, 2, 200))
|
51
|
+
assert_equal(8, r.bitpos("foo", 1, 1, 1))
|
58
52
|
end
|
59
53
|
end
|
60
54
|
|
@@ -1,12 +1,153 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/blocking_commands"
|
1
|
+
require_relative "helper"
|
5
2
|
|
6
3
|
class TestBlockingCommands < Test::Unit::TestCase
|
7
4
|
|
8
5
|
include Helper::Client
|
9
|
-
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
|
10
|
+
r.rpush("{zap}foo", "s1")
|
11
|
+
r.rpush("{zap}foo", "s2")
|
12
|
+
r.rpush("{zap}bar", "s1")
|
13
|
+
r.rpush("{zap}bar", "s2")
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_protocol(obj)
|
17
|
+
case obj
|
18
|
+
when String
|
19
|
+
"$#{obj.length}\r\n#{obj}\r\n"
|
20
|
+
when Array
|
21
|
+
"*#{obj.length}\r\n" + obj.map { |e| to_protocol(e) }.join
|
22
|
+
else
|
23
|
+
fail
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def mock(options = {}, &blk)
|
28
|
+
commands = {
|
29
|
+
:blpop => lambda do |*args|
|
30
|
+
sleep options[:delay] if options.has_key?(:delay)
|
31
|
+
to_protocol([args.first, args.last])
|
32
|
+
end,
|
33
|
+
:brpop => lambda do |*args|
|
34
|
+
sleep options[:delay] if options.has_key?(:delay)
|
35
|
+
to_protocol([args.first, args.last])
|
36
|
+
end,
|
37
|
+
:brpoplpush => lambda do |*args|
|
38
|
+
sleep options[:delay] if options.has_key?(:delay)
|
39
|
+
to_protocol(args.last)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
redis_mock(commands, &blk)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_blpop
|
47
|
+
assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo")
|
48
|
+
assert_equal ["{zap}foo", "s2"], r.blpop(["{zap}foo"])
|
49
|
+
assert_equal ["{zap}bar", "s1"], r.blpop(["{zap}bar", "{zap}foo"])
|
50
|
+
assert_equal ["{zap}bar", "s2"], r.blpop(["{zap}foo", "{zap}bar"])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_blpop_timeout
|
54
|
+
mock do |r|
|
55
|
+
assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo")
|
56
|
+
assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", :timeout => 1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_blpop_with_old_prototype
|
61
|
+
assert_equal ["{zap}foo", "s1"], r.blpop("{zap}foo", 0)
|
62
|
+
assert_equal ["{zap}foo", "s2"], r.blpop("{zap}foo", 0)
|
63
|
+
assert_equal ["{zap}bar", "s1"], r.blpop("{zap}bar", "{zap}foo", 0)
|
64
|
+
assert_equal ["{zap}bar", "s2"], r.blpop("{zap}foo", "{zap}bar", 0)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_blpop_timeout_with_old_prototype
|
68
|
+
mock do |r|
|
69
|
+
assert_equal ["{zap}foo", "0"], r.blpop("{zap}foo", 0)
|
70
|
+
assert_equal ["{zap}foo", "1"], r.blpop("{zap}foo", 1)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_brpop
|
75
|
+
assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo")
|
76
|
+
assert_equal ["{zap}foo", "s1"], r.brpop(["{zap}foo"])
|
77
|
+
assert_equal ["{zap}bar", "s2"], r.brpop(["{zap}bar", "{zap}foo"])
|
78
|
+
assert_equal ["{zap}bar", "s1"], r.brpop(["{zap}foo", "{zap}bar"])
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_brpop_timeout
|
82
|
+
mock do |r|
|
83
|
+
assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo")
|
84
|
+
assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", :timeout => 1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_brpop_with_old_prototype
|
89
|
+
assert_equal ["{zap}foo", "s2"], r.brpop("{zap}foo", 0)
|
90
|
+
assert_equal ["{zap}foo", "s1"], r.brpop("{zap}foo", 0)
|
91
|
+
assert_equal ["{zap}bar", "s2"], r.brpop("{zap}bar", "{zap}foo", 0)
|
92
|
+
assert_equal ["{zap}bar", "s1"], r.brpop("{zap}foo", "{zap}bar", 0)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_brpop_timeout_with_old_prototype
|
96
|
+
mock do |r|
|
97
|
+
assert_equal ["{zap}foo", "0"], r.brpop("{zap}foo", 0)
|
98
|
+
assert_equal ["{zap}foo", "1"], r.brpop("{zap}foo", 1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_brpoplpush
|
103
|
+
assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux")
|
104
|
+
assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_brpoplpush_timeout
|
108
|
+
mock do |r|
|
109
|
+
assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar")
|
110
|
+
assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", :timeout => 1)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_brpoplpush_with_old_prototype
|
115
|
+
assert_equal "s2", r.brpoplpush("{zap}foo", "{zap}qux", 0)
|
116
|
+
assert_equal ["s2"], r.lrange("{zap}qux", 0, -1)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_brpoplpush_timeout_with_old_prototype
|
120
|
+
mock do |r|
|
121
|
+
assert_equal "0", r.brpoplpush("{zap}foo", "{zap}bar", 0)
|
122
|
+
assert_equal "1", r.brpoplpush("{zap}foo", "{zap}bar", 1)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
driver(:ruby, :hiredis) do
|
127
|
+
def test_blpop_socket_timeout
|
128
|
+
mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
|
129
|
+
assert_raises(Redis::TimeoutError) do
|
130
|
+
r.blpop("{zap}foo", :timeout => 1)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_brpop_socket_timeout
|
136
|
+
mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
|
137
|
+
assert_raises(Redis::TimeoutError) do
|
138
|
+
r.brpop("{zap}foo", :timeout => 1)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_brpoplpush_socket_timeout
|
144
|
+
mock(:delay => 1 + OPTIONS[:timeout] * 2) do |r|
|
145
|
+
assert_raises(Redis::TimeoutError) do
|
146
|
+
r.brpoplpush("{zap}foo", "{zap}bar", :timeout => 1)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
10
151
|
|
11
152
|
def assert_takes_longer_than_client_timeout
|
12
153
|
timeout = OPTIONS[:timeout]
|
@@ -17,7 +158,7 @@ class TestBlockingCommands < Test::Unit::TestCase
|
|
17
158
|
yield(r)
|
18
159
|
t2 = Time.now
|
19
160
|
|
20
|
-
assert timeout == r.
|
161
|
+
assert timeout == r._client.timeout
|
21
162
|
assert delay <= (t2 - t1)
|
22
163
|
end
|
23
164
|
end
|