redis 4.0.1 → 4.0.3
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +17 -29
- data/.travis/Gemfile +5 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/bin/build +71 -0
- data/lib/redis.rb +198 -12
- data/lib/redis/client.rb +26 -12
- data/lib/redis/cluster.rb +285 -0
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +32 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +104 -0
- data/lib/redis/cluster/node_key.rb +35 -0
- data/lib/redis/cluster/node_loader.rb +35 -0
- data/lib/redis/cluster/option.rb +76 -0
- data/lib/redis/cluster/slot.rb +69 -0
- data/lib/redis/cluster/slot_loader.rb +47 -0
- data/lib/redis/connection/ruby.rb +5 -2
- data/lib/redis/distributed.rb +10 -2
- data/lib/redis/errors.rb +46 -0
- data/lib/redis/pipeline.rb +9 -1
- data/lib/redis/version.rb +1 -1
- data/makefile +54 -22
- data/redis.gemspec +2 -1
- data/test/client_test.rb +17 -0
- data/test/cluster_abnormal_state_test.rb +38 -0
- data/test/cluster_blocking_commands_test.rb +15 -0
- data/test/cluster_client_internals_test.rb +77 -0
- data/test/cluster_client_key_hash_tags_test.rb +88 -0
- data/test/cluster_client_options_test.rb +147 -0
- data/test/cluster_client_pipelining_test.rb +59 -0
- data/test/cluster_client_replicas_test.rb +36 -0
- data/test/cluster_client_slots_test.rb +94 -0
- data/test/cluster_client_transactions_test.rb +71 -0
- data/test/cluster_commands_on_cluster_test.rb +165 -0
- data/test/cluster_commands_on_connection_test.rb +40 -0
- data/test/cluster_commands_on_geo_test.rb +74 -0
- data/test/cluster_commands_on_hashes_test.rb +11 -0
- data/test/cluster_commands_on_hyper_log_log_test.rb +17 -0
- data/test/cluster_commands_on_keys_test.rb +134 -0
- data/test/cluster_commands_on_lists_test.rb +15 -0
- data/test/cluster_commands_on_pub_sub_test.rb +101 -0
- data/test/cluster_commands_on_scripting_test.rb +56 -0
- data/test/cluster_commands_on_server_test.rb +221 -0
- data/test/cluster_commands_on_sets_test.rb +39 -0
- data/test/cluster_commands_on_sorted_sets_test.rb +35 -0
- data/test/cluster_commands_on_streams_test.rb +196 -0
- data/test/cluster_commands_on_strings_test.rb +15 -0
- data/test/cluster_commands_on_transactions_test.rb +41 -0
- data/test/cluster_commands_on_value_types_test.rb +14 -0
- data/test/commands_on_geo_test.rb +116 -0
- data/test/commands_on_hashes_test.rb +2 -14
- data/test/commands_on_hyper_log_log_test.rb +2 -14
- data/test/commands_on_lists_test.rb +2 -13
- data/test/commands_on_sets_test.rb +2 -70
- data/test/commands_on_sorted_sets_test.rb +2 -145
- data/test/commands_on_strings_test.rb +2 -94
- data/test/commands_on_value_types_test.rb +36 -0
- data/test/distributed_blocking_commands_test.rb +8 -0
- data/test/distributed_commands_on_hashes_test.rb +16 -3
- data/test/distributed_commands_on_hyper_log_log_test.rb +8 -13
- data/test/distributed_commands_on_lists_test.rb +4 -5
- data/test/distributed_commands_on_sets_test.rb +45 -46
- data/test/distributed_commands_on_sorted_sets_test.rb +51 -8
- data/test/distributed_commands_on_strings_test.rb +10 -0
- data/test/distributed_commands_on_value_types_test.rb +36 -0
- data/test/helper.rb +176 -32
- data/test/internals_test.rb +20 -1
- data/test/lint/blocking_commands.rb +40 -16
- data/test/lint/hashes.rb +41 -0
- data/test/lint/hyper_log_log.rb +15 -1
- data/test/lint/lists.rb +16 -0
- data/test/lint/sets.rb +142 -0
- data/test/lint/sorted_sets.rb +183 -2
- data/test/lint/strings.rb +102 -0
- data/test/pipelining_commands_test.rb +8 -0
- data/test/support/cluster/orchestrator.rb +199 -0
- data/test/support/redis_mock.rb +1 -1
- data/test/transactions_test.rb +10 -0
- metadata +81 -2
@@ -1,99 +1,7 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/strings'
|
3
3
|
|
4
4
|
class TestCommandsOnStrings < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Client
|
7
6
|
include Lint::Strings
|
8
|
-
|
9
|
-
def test_mget
|
10
|
-
r.set("foo", "s1")
|
11
|
-
r.set("bar", "s2")
|
12
|
-
|
13
|
-
assert_equal ["s1", "s2"] , r.mget("foo", "bar")
|
14
|
-
assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_mget_mapped
|
18
|
-
r.set("foo", "s1")
|
19
|
-
r.set("bar", "s2")
|
20
|
-
|
21
|
-
response = r.mapped_mget("foo", "bar")
|
22
|
-
|
23
|
-
assert_equal "s1", response["foo"]
|
24
|
-
assert_equal "s2", response["bar"]
|
25
|
-
|
26
|
-
response = r.mapped_mget("foo", "bar", "baz")
|
27
|
-
|
28
|
-
assert_equal "s1", response["foo"]
|
29
|
-
assert_equal "s2", response["bar"]
|
30
|
-
assert_equal nil , response["baz"]
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_mapped_mget_in_a_pipeline_returns_hash
|
34
|
-
r.set("foo", "s1")
|
35
|
-
r.set("bar", "s2")
|
36
|
-
|
37
|
-
result = r.pipelined do
|
38
|
-
r.mapped_mget("foo", "bar")
|
39
|
-
end
|
40
|
-
|
41
|
-
assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_mset
|
45
|
-
r.mset(:foo, "s1", :bar, "s2")
|
46
|
-
|
47
|
-
assert_equal "s1", r.get("foo")
|
48
|
-
assert_equal "s2", r.get("bar")
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_mset_mapped
|
52
|
-
r.mapped_mset(:foo => "s1", :bar => "s2")
|
53
|
-
|
54
|
-
assert_equal "s1", r.get("foo")
|
55
|
-
assert_equal "s2", r.get("bar")
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_msetnx
|
59
|
-
r.set("foo", "s1")
|
60
|
-
assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
|
61
|
-
assert_equal "s1", r.get("foo")
|
62
|
-
assert_equal nil, r.get("bar")
|
63
|
-
|
64
|
-
r.del("foo")
|
65
|
-
assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
|
66
|
-
assert_equal "s2", r.get("foo")
|
67
|
-
assert_equal "s3", r.get("bar")
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_msetnx_mapped
|
71
|
-
r.set("foo", "s1")
|
72
|
-
assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
73
|
-
assert_equal "s1", r.get("foo")
|
74
|
-
assert_equal nil, r.get("bar")
|
75
|
-
|
76
|
-
r.del("foo")
|
77
|
-
assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
78
|
-
assert_equal "s2", r.get("foo")
|
79
|
-
assert_equal "s3", r.get("bar")
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_bitop
|
83
|
-
with_external_encoding("UTF-8") do
|
84
|
-
target_version "2.5.10" do
|
85
|
-
r.set("foo", "a")
|
86
|
-
r.set("bar", "b")
|
87
|
-
|
88
|
-
r.bitop(:and, "foo&bar", "foo", "bar")
|
89
|
-
assert_equal "\x60", r.get("foo&bar")
|
90
|
-
r.bitop(:or, "foo|bar", "foo", "bar")
|
91
|
-
assert_equal "\x63", r.get("foo|bar")
|
92
|
-
r.bitop(:xor, "foo^bar", "foo", "bar")
|
93
|
-
assert_equal "\x03", r.get("foo^bar")
|
94
|
-
r.bitop(:not, "~foo", "foo")
|
95
|
-
assert_equal "\x9E", r.get("~foo")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
7
|
end
|
@@ -38,6 +38,42 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
|
|
38
38
|
assert_equal [], r.keys("*").sort
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_unlink
|
42
|
+
target_version "4.0.0" do
|
43
|
+
r.set "foo", "s1"
|
44
|
+
r.set "bar", "s2"
|
45
|
+
r.set "baz", "s3"
|
46
|
+
|
47
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
48
|
+
|
49
|
+
assert_equal 1, r.unlink("foo")
|
50
|
+
|
51
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
52
|
+
|
53
|
+
assert_equal 2, r.unlink("bar", "baz")
|
54
|
+
|
55
|
+
assert_equal [], r.keys("*").sort
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_unlink_with_array_argument
|
60
|
+
target_version "4.0.0" do
|
61
|
+
r.set "foo", "s1"
|
62
|
+
r.set "bar", "s2"
|
63
|
+
r.set "baz", "s3"
|
64
|
+
|
65
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
66
|
+
|
67
|
+
assert_equal 1, r.unlink(["foo"])
|
68
|
+
|
69
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
70
|
+
|
71
|
+
assert_equal 2, r.unlink(["bar", "baz"])
|
72
|
+
|
73
|
+
assert_equal [], r.keys("*").sort
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
41
77
|
def test_randomkey
|
42
78
|
assert r.randomkey.to_s.empty?
|
43
79
|
|
@@ -1,8 +1,21 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/hashes'
|
3
3
|
|
4
4
|
class TestDistributedCommandsOnHashes < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Distributed
|
7
6
|
include Lint::Hashes
|
7
|
+
|
8
|
+
def test_hscan
|
9
|
+
# Not implemented yet
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_hstrlen
|
13
|
+
# Not implemented yet
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_mapped_hmget_in_a_pipeline_returns_hash
|
17
|
+
assert_raise(Redis::Distributed::CannotDistribute) do
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
8
21
|
end
|
@@ -1,31 +1,26 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/hyper_log_log'
|
3
3
|
|
4
4
|
class TestDistributedCommandsOnHyperLogLog < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Distributed
|
7
6
|
include Lint::HyperLogLog
|
8
7
|
|
9
8
|
def test_pfmerge
|
10
|
-
target_version
|
9
|
+
target_version '2.8.9' do
|
11
10
|
assert_raise Redis::Distributed::CannotDistribute do
|
12
|
-
|
13
|
-
r.pfadd "bar", "s2"
|
14
|
-
|
15
|
-
assert r.pfmerge("res", "foo", "bar")
|
11
|
+
super
|
16
12
|
end
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
20
16
|
def test_pfcount_multiple_keys_diff_nodes
|
21
|
-
target_version
|
17
|
+
target_version '2.8.9' do
|
22
18
|
assert_raise Redis::Distributed::CannotDistribute do
|
23
|
-
r.pfadd
|
24
|
-
r.pfadd
|
19
|
+
r.pfadd 'foo', 's1'
|
20
|
+
r.pfadd 'bar', 's2'
|
25
21
|
|
26
|
-
assert r.pfcount(
|
22
|
+
assert r.pfcount('res', 'foo', 'bar')
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
30
|
-
|
31
26
|
end
|
@@ -1,20 +1,19 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/lists'
|
3
3
|
|
4
4
|
class TestDistributedCommandsOnLists < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Distributed
|
7
6
|
include Lint::Lists
|
8
7
|
|
9
8
|
def test_rpoplpush
|
10
9
|
assert_raise Redis::Distributed::CannotDistribute do
|
11
|
-
r.rpoplpush(
|
10
|
+
r.rpoplpush('foo', 'bar')
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
def test_brpoplpush
|
16
15
|
assert_raise Redis::Distributed::CannotDistribute do
|
17
|
-
r.brpoplpush(
|
16
|
+
r.brpoplpush('foo', 'bar', timeout: 1)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -1,106 +1,105 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/sets'
|
3
3
|
|
4
4
|
class TestDistributedCommandsOnSets < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Distributed
|
7
6
|
include Lint::Sets
|
8
7
|
|
9
8
|
def test_smove
|
10
9
|
assert_raise Redis::Distributed::CannotDistribute do
|
11
|
-
r.sadd
|
12
|
-
r.sadd
|
10
|
+
r.sadd 'foo', 's1'
|
11
|
+
r.sadd 'bar', 's2'
|
13
12
|
|
14
|
-
r.smove(
|
13
|
+
r.smove('foo', 'bar', 's1')
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_sinter
|
19
18
|
assert_raise Redis::Distributed::CannotDistribute do
|
20
|
-
r.sadd
|
21
|
-
r.sadd
|
22
|
-
r.sadd
|
19
|
+
r.sadd 'foo', 's1'
|
20
|
+
r.sadd 'foo', 's2'
|
21
|
+
r.sadd 'bar', 's2'
|
23
22
|
|
24
|
-
r.sinter(
|
23
|
+
r.sinter('foo', 'bar')
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_sinterstore
|
29
28
|
assert_raise Redis::Distributed::CannotDistribute do
|
30
|
-
r.sadd
|
31
|
-
r.sadd
|
32
|
-
r.sadd
|
29
|
+
r.sadd 'foo', 's1'
|
30
|
+
r.sadd 'foo', 's2'
|
31
|
+
r.sadd 'bar', 's2'
|
33
32
|
|
34
|
-
r.sinterstore(
|
33
|
+
r.sinterstore('baz', 'foo', 'bar')
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
def test_sunion
|
39
38
|
assert_raise Redis::Distributed::CannotDistribute do
|
40
|
-
r.sadd
|
41
|
-
r.sadd
|
42
|
-
r.sadd
|
43
|
-
r.sadd
|
39
|
+
r.sadd 'foo', 's1'
|
40
|
+
r.sadd 'foo', 's2'
|
41
|
+
r.sadd 'bar', 's2'
|
42
|
+
r.sadd 'bar', 's3'
|
44
43
|
|
45
|
-
r.sunion(
|
44
|
+
r.sunion('foo', 'bar')
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
def test_sunionstore
|
50
49
|
assert_raise Redis::Distributed::CannotDistribute do
|
51
|
-
r.sadd
|
52
|
-
r.sadd
|
53
|
-
r.sadd
|
54
|
-
r.sadd
|
50
|
+
r.sadd 'foo', 's1'
|
51
|
+
r.sadd 'foo', 's2'
|
52
|
+
r.sadd 'bar', 's2'
|
53
|
+
r.sadd 'bar', 's3'
|
55
54
|
|
56
|
-
r.sunionstore(
|
55
|
+
r.sunionstore('baz', 'foo', 'bar')
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
59
|
def test_sdiff
|
61
60
|
assert_raise Redis::Distributed::CannotDistribute do
|
62
|
-
r.sadd
|
63
|
-
r.sadd
|
64
|
-
r.sadd
|
65
|
-
r.sadd
|
61
|
+
r.sadd 'foo', 's1'
|
62
|
+
r.sadd 'foo', 's2'
|
63
|
+
r.sadd 'bar', 's2'
|
64
|
+
r.sadd 'bar', 's3'
|
66
65
|
|
67
|
-
r.sdiff(
|
66
|
+
r.sdiff('foo', 'bar')
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
def test_sdiffstore
|
72
71
|
assert_raise Redis::Distributed::CannotDistribute do
|
73
|
-
r.sadd
|
74
|
-
r.sadd
|
75
|
-
r.sadd
|
76
|
-
r.sadd
|
72
|
+
r.sadd 'foo', 's1'
|
73
|
+
r.sadd 'foo', 's2'
|
74
|
+
r.sadd 'bar', 's2'
|
75
|
+
r.sadd 'bar', 's3'
|
77
76
|
|
78
|
-
r.sdiffstore(
|
77
|
+
r.sdiffstore('baz', 'foo', 'bar')
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
def test_sscan
|
83
82
|
assert_nothing_raised do
|
84
|
-
r.sadd
|
85
|
-
r.sadd
|
86
|
-
r.sadd
|
87
|
-
r.sadd
|
83
|
+
r.sadd 'foo', 's1'
|
84
|
+
r.sadd 'foo', 's2'
|
85
|
+
r.sadd 'bar', 's2'
|
86
|
+
r.sadd 'bar', 's3'
|
88
87
|
|
89
|
-
cursor, vals = r.sscan
|
88
|
+
cursor, vals = r.sscan 'foo', 0
|
90
89
|
assert_equal '0', cursor
|
91
|
-
assert_equal %w
|
90
|
+
assert_equal %w[s1 s2], vals.sort
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
95
94
|
def test_sscan_each
|
96
95
|
assert_nothing_raised do
|
97
|
-
r.sadd
|
98
|
-
r.sadd
|
99
|
-
r.sadd
|
100
|
-
r.sadd
|
96
|
+
r.sadd 'foo', 's1'
|
97
|
+
r.sadd 'foo', 's2'
|
98
|
+
r.sadd 'bar', 's2'
|
99
|
+
r.sadd 'bar', 's3'
|
101
100
|
|
102
|
-
vals = r.sscan_each(
|
103
|
-
assert_equal %w
|
101
|
+
vals = r.sscan_each('foo').to_a
|
102
|
+
assert_equal %w[s1 s2], vals.sort
|
104
103
|
end
|
105
104
|
end
|
106
105
|
end
|
@@ -1,16 +1,59 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/sorted_sets'
|
3
3
|
|
4
4
|
class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
|
5
|
-
|
6
5
|
include Helper::Distributed
|
7
6
|
include Lint::SortedSets
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def test_zinterstore
|
9
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_zinterstore_with_aggregate
|
13
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_zinterstore_with_weights
|
17
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_zlexcount
|
21
|
+
# Not implemented yet
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_zpopmax
|
25
|
+
# Not implemented yet
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_zpopmin
|
29
|
+
# Not implemented yet
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_zrangebylex
|
33
|
+
# Not implemented yet
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_zremrangebylex
|
37
|
+
# Not implemented yet
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_zrevrangebylex
|
41
|
+
# Not implemented yet
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_zscan
|
45
|
+
# Not implemented yet
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_zunionstore
|
49
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_zunionstore_with_aggregate
|
53
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
54
|
+
end
|
13
55
|
|
14
|
-
|
56
|
+
def test_zunionstore_with_weights
|
57
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
15
58
|
end
|
16
59
|
end
|