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
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestDistributedRemoteServerControlCommands < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Distributed
|
8
|
-
|
9
|
-
def test_info
|
10
|
-
keys = [
|
11
|
-
"redis_version",
|
12
|
-
"uptime_in_seconds",
|
13
|
-
"uptime_in_days",
|
14
|
-
"connected_clients",
|
15
|
-
"used_memory",
|
16
|
-
"total_connections_received",
|
17
|
-
"total_commands_processed",
|
18
|
-
]
|
19
|
-
|
20
|
-
infos = r.info
|
21
|
-
|
22
|
-
infos.each do |info|
|
23
|
-
keys.each do |k|
|
24
|
-
msg = "expected #info to include #{k}"
|
25
|
-
assert info.keys.include?(k), msg
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_info_commandstats
|
31
|
-
target_version "2.5.7" do
|
32
|
-
r.nodes.each { |n| n.config(:resetstat) }
|
33
|
-
r.ping # Executed on every node
|
34
|
-
|
35
|
-
r.info(:commandstats).each do |info|
|
36
|
-
assert_equal "1", info["ping"]["calls"]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_monitor
|
42
|
-
begin
|
43
|
-
r.monitor
|
44
|
-
rescue Exception => ex
|
45
|
-
ensure
|
46
|
-
assert ex.kind_of?(NotImplementedError)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_echo
|
51
|
-
assert_equal ["foo bar baz\n"], r.echo("foo bar baz\n")
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_time
|
55
|
-
target_version "2.5.4" do
|
56
|
-
# Test that the difference between the time that Ruby reports and the time
|
57
|
-
# that Redis reports is minimal (prevents the test from being racy).
|
58
|
-
r.time.each do |rv|
|
59
|
-
redis_usec = rv[0] * 1_000_000 + rv[1]
|
60
|
-
ruby_usec = Integer(Time.now.to_f * 1_000_000)
|
61
|
-
|
62
|
-
assert 500_000 > (ruby_usec - redis_usec).abs
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestDistributedScripting < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Distributed
|
8
|
-
|
9
|
-
def to_sha(script)
|
10
|
-
r.script(:load, script).first
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_script_exists
|
14
|
-
target_version "2.5.9" do # 2.6-rc1
|
15
|
-
a = to_sha("return 1")
|
16
|
-
b = a.succ
|
17
|
-
|
18
|
-
assert_equal [true], r.script(:exists, a)
|
19
|
-
assert_equal [false], r.script(:exists, b)
|
20
|
-
assert_equal [[true]], r.script(:exists, [a])
|
21
|
-
assert_equal [[false]], r.script(:exists, [b])
|
22
|
-
assert_equal [[true, false]], r.script(:exists, [a, b])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_script_flush
|
27
|
-
target_version "2.5.9" do # 2.6-rc1
|
28
|
-
sha = to_sha("return 1")
|
29
|
-
assert r.script(:exists, sha).first
|
30
|
-
assert_equal ["OK"], r.script(:flush)
|
31
|
-
assert !r.script(:exists, sha).first
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_script_kill
|
36
|
-
target_version "2.5.9" do # 2.6-rc1
|
37
|
-
redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
|
38
|
-
assert_equal ["KILL"], redis.script(:kill)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_eval
|
44
|
-
target_version "2.5.9" do # 2.6-rc1
|
45
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
46
|
-
r.eval("return #KEYS")
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
50
|
-
r.eval("return KEYS", ["k1", "k2"])
|
51
|
-
end
|
52
|
-
|
53
|
-
assert_equal ["k1"], r.eval("return KEYS", ["k1"])
|
54
|
-
assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_eval_with_options_hash
|
59
|
-
target_version "2.5.9" do # 2.6-rc1
|
60
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
61
|
-
r.eval("return #KEYS", {})
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
65
|
-
r.eval("return KEYS", { :keys => ["k1", "k2"] })
|
66
|
-
end
|
67
|
-
|
68
|
-
assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
|
69
|
-
assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_evalsha
|
74
|
-
target_version "2.5.9" do # 2.6-rc1
|
75
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
76
|
-
r.evalsha(to_sha("return #KEYS"))
|
77
|
-
end
|
78
|
-
|
79
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
80
|
-
r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
|
84
|
-
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_evalsha_with_options_hash
|
89
|
-
target_version "2.5.9" do # 2.6-rc1
|
90
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
91
|
-
r.evalsha(to_sha("return #KEYS"), {})
|
92
|
-
end
|
93
|
-
|
94
|
-
assert_raises(Redis::Distributed::CannotDistribute) do
|
95
|
-
r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
|
96
|
-
end
|
97
|
-
|
98
|
-
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
|
99
|
-
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestDistributedSorting < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Distributed
|
8
|
-
|
9
|
-
def test_sort
|
10
|
-
assert_raise(Redis::Distributed::CannotDistribute) do
|
11
|
-
r.set("foo:1", "s1")
|
12
|
-
r.set("foo:2", "s2")
|
13
|
-
|
14
|
-
r.rpush("bar", "1")
|
15
|
-
r.rpush("bar", "2")
|
16
|
-
|
17
|
-
r.sort("bar", :get => "foo:*", :limit => [0, 1])
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/test/distributed_test.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestDistributed < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Distributed
|
8
|
-
|
9
|
-
def test_handle_multiple_servers
|
10
|
-
@r = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
|
11
|
-
|
12
|
-
100.times do |idx|
|
13
|
-
@r.set(idx.to_s, "foo#{idx}")
|
14
|
-
end
|
15
|
-
|
16
|
-
100.times do |idx|
|
17
|
-
assert_equal "foo#{idx}", @r.get(idx.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_equal "0", @r.keys("*").sort.first
|
21
|
-
assert_equal "string", @r.type("1")
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_add_nodes
|
25
|
-
logger = Logger.new("/dev/null")
|
26
|
-
|
27
|
-
@r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
|
28
|
-
|
29
|
-
assert_equal "127.0.0.1", @r.nodes[0].client.host
|
30
|
-
assert_equal PORT, @r.nodes[0].client.port
|
31
|
-
assert_equal 15, @r.nodes[0].client.db
|
32
|
-
assert_equal 10, @r.nodes[0].client.timeout
|
33
|
-
assert_equal logger, @r.nodes[0].client.logger
|
34
|
-
|
35
|
-
@r.add_node("redis://127.0.0.1:6380/14")
|
36
|
-
|
37
|
-
assert_equal "127.0.0.1", @r.nodes[1].client.host
|
38
|
-
assert_equal 6380, @r.nodes[1].client.port
|
39
|
-
assert_equal 14, @r.nodes[1].client.db
|
40
|
-
assert_equal 10, @r.nodes[1].client.timeout
|
41
|
-
assert_equal logger, @r.nodes[1].client.logger
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_pipelining_commands_cannot_be_distributed
|
45
|
-
assert_raise Redis::Distributed::CannotDistribute do
|
46
|
-
r.pipelined do
|
47
|
-
r.lpush "foo", "s1"
|
48
|
-
r.lpush "foo", "s2"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_unknown_commands_does_not_work_by_default
|
54
|
-
assert_raise NoMethodError do
|
55
|
-
r.not_yet_implemented_command
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestDistributedTransactions < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Distributed
|
8
|
-
|
9
|
-
def test_multi_discard
|
10
|
-
@foo = nil
|
11
|
-
|
12
|
-
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
-
r.multi { @foo = 1 }
|
14
|
-
end
|
15
|
-
|
16
|
-
assert_equal nil, @foo
|
17
|
-
|
18
|
-
assert_raise Redis::Distributed::CannotDistribute do
|
19
|
-
r.discard
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_watch_unwatch
|
24
|
-
assert_raise Redis::Distributed::CannotDistribute do
|
25
|
-
r.watch("foo")
|
26
|
-
end
|
27
|
-
|
28
|
-
assert_raise Redis::Distributed::CannotDistribute do
|
29
|
-
r.unwatch
|
30
|
-
end
|
31
|
-
end
|
32
|
-
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
|