redis 4.0.0.rc1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -6
- data/.travis/Gemfile +3 -1
- data/CHANGELOG.md +6 -2
- data/README.md +5 -5
- data/bors.toml +14 -0
- data/examples/dist_redis.rb +43 -0
- data/lib/redis.rb +37 -6
- data/lib/redis/client.rb +5 -6
- data/lib/redis/connection/ruby.rb +1 -1
- data/lib/redis/connection/synchrony.rb +9 -1
- data/lib/redis/distributed.rb +873 -0
- data/lib/redis/hash_ring.rb +88 -0
- data/lib/redis/version.rb +1 -1
- data/redis.gemspec +3 -1
- data/test/blocking_commands_test.rb +2 -145
- data/test/commands_on_hashes_test.rb +2 -157
- data/test/commands_on_hyper_log_log_test.rb +2 -53
- data/test/commands_on_lists_test.rb +2 -138
- data/test/commands_on_sets_test.rb +2 -135
- data/test/commands_on_sorted_sets_test.rb +13 -307
- data/test/commands_on_strings_test.rb +2 -241
- data/test/commands_on_value_types_test.rb +2 -117
- data/test/distributed_blocking_commands_test.rb +44 -0
- data/test/distributed_commands_on_hashes_test.rb +8 -0
- data/test/distributed_commands_on_hyper_log_log_test.rb +31 -0
- data/test/distributed_commands_on_lists_test.rb +20 -0
- data/test/distributed_commands_on_sets_test.rb +81 -0
- data/test/distributed_commands_on_sorted_sets_test.rb +16 -0
- data/test/distributed_commands_on_strings_test.rb +57 -0
- data/test/distributed_commands_on_value_types_test.rb +93 -0
- data/test/distributed_commands_requiring_clustering_test.rb +162 -0
- data/test/distributed_connection_handling_test.rb +21 -0
- data/test/distributed_internals_test.rb +68 -0
- data/test/distributed_key_tags_test.rb +50 -0
- data/test/distributed_persistence_control_commands_test.rb +24 -0
- data/test/distributed_publish_subscribe_test.rb +90 -0
- data/test/distributed_remote_server_control_commands_test.rb +64 -0
- data/test/distributed_scripting_test.rb +100 -0
- data/test/distributed_sorting_test.rb +18 -0
- data/test/distributed_test.rb +56 -0
- data/test/distributed_transactions_test.rb +30 -0
- data/test/helper.rb +22 -0
- data/test/internals_test.rb +7 -13
- data/test/lint/blocking_commands.rb +150 -0
- data/test/lint/hashes.rb +162 -0
- data/test/lint/hyper_log_log.rb +60 -0
- data/test/lint/lists.rb +143 -0
- data/test/lint/sets.rb +140 -0
- data/test/lint/sorted_sets.rb +316 -0
- data/test/lint/strings.rb +246 -0
- data/test/lint/value_types.rb +130 -0
- data/test/remote_server_control_commands_test.rb +1 -1
- metadata +66 -8
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/lists"
|
3
|
+
|
4
|
+
class TestDistributedCommandsOnLists < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Helper::Distributed
|
7
|
+
include Lint::Lists
|
8
|
+
|
9
|
+
def test_rpoplpush
|
10
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
11
|
+
r.rpoplpush("foo", "bar")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_brpoplpush
|
16
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
17
|
+
r.brpoplpush("foo", "bar", :timeout => 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/sets"
|
3
|
+
|
4
|
+
class TestDistributedCommandsOnSets < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Helper::Distributed
|
7
|
+
include Lint::Sets
|
8
|
+
|
9
|
+
def test_smove
|
10
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
11
|
+
r.sadd "foo", "s1"
|
12
|
+
r.sadd "bar", "s2"
|
13
|
+
|
14
|
+
r.smove("foo", "bar", "s1")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_sinter
|
19
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
20
|
+
r.sadd "foo", "s1"
|
21
|
+
r.sadd "foo", "s2"
|
22
|
+
r.sadd "bar", "s2"
|
23
|
+
|
24
|
+
r.sinter("foo", "bar")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sinterstore
|
29
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
30
|
+
r.sadd "foo", "s1"
|
31
|
+
r.sadd "foo", "s2"
|
32
|
+
r.sadd "bar", "s2"
|
33
|
+
|
34
|
+
r.sinterstore("baz", "foo", "bar")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_sunion
|
39
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
40
|
+
r.sadd "foo", "s1"
|
41
|
+
r.sadd "foo", "s2"
|
42
|
+
r.sadd "bar", "s2"
|
43
|
+
r.sadd "bar", "s3"
|
44
|
+
|
45
|
+
r.sunion("foo", "bar")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_sunionstore
|
50
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
51
|
+
r.sadd "foo", "s1"
|
52
|
+
r.sadd "foo", "s2"
|
53
|
+
r.sadd "bar", "s2"
|
54
|
+
r.sadd "bar", "s3"
|
55
|
+
|
56
|
+
r.sunionstore("baz", "foo", "bar")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_sdiff
|
61
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
62
|
+
r.sadd "foo", "s1"
|
63
|
+
r.sadd "foo", "s2"
|
64
|
+
r.sadd "bar", "s2"
|
65
|
+
r.sadd "bar", "s3"
|
66
|
+
|
67
|
+
r.sdiff("foo", "bar")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_sdiffstore
|
72
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
73
|
+
r.sadd "foo", "s1"
|
74
|
+
r.sadd "foo", "s2"
|
75
|
+
r.sadd "bar", "s2"
|
76
|
+
r.sadd "bar", "s3"
|
77
|
+
|
78
|
+
r.sdiffstore("baz", "foo", "bar")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/sorted_sets"
|
3
|
+
|
4
|
+
class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Helper::Distributed
|
7
|
+
include Lint::SortedSets
|
8
|
+
|
9
|
+
def test_zcount
|
10
|
+
r.zadd "foo", 1, "s1"
|
11
|
+
r.zadd "foo", 2, "s2"
|
12
|
+
r.zadd "foo", 3, "s3"
|
13
|
+
|
14
|
+
assert_equal 2, r.zcount("foo", 2, 3)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/strings"
|
3
|
+
|
4
|
+
class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Helper::Distributed
|
7
|
+
include Lint::Strings
|
8
|
+
|
9
|
+
def test_mget
|
10
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
11
|
+
r.mget("foo", "bar")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_mget_mapped
|
16
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
17
|
+
r.mapped_mget("foo", "bar")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_mset
|
22
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
23
|
+
r.mset(:foo, "s1", :bar, "s2")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_mset_mapped
|
28
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
29
|
+
r.mapped_mset(:foo => "s1", :bar => "s2")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_msetnx
|
34
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
35
|
+
r.set("foo", "s1")
|
36
|
+
r.msetnx(:foo, "s2", :bar, "s3")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_msetnx_mapped
|
41
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
42
|
+
r.set("foo", "s1")
|
43
|
+
r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_bitop
|
48
|
+
target_version "2.5.10" do
|
49
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
50
|
+
r.set("foo", "a")
|
51
|
+
r.set("bar", "b")
|
52
|
+
|
53
|
+
r.bitop(:and, "foo&bar", "foo", "bar")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/value_types"
|
3
|
+
|
4
|
+
class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Helper::Distributed
|
7
|
+
include Lint::ValueTypes
|
8
|
+
|
9
|
+
def test_del
|
10
|
+
r.set "foo", "s1"
|
11
|
+
r.set "bar", "s2"
|
12
|
+
r.set "baz", "s3"
|
13
|
+
|
14
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
15
|
+
|
16
|
+
assert_equal 1, r.del("foo")
|
17
|
+
|
18
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
19
|
+
|
20
|
+
assert_equal 2, r.del("bar", "baz")
|
21
|
+
|
22
|
+
assert_equal [], r.keys("*").sort
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_del_with_array_argument
|
26
|
+
r.set "foo", "s1"
|
27
|
+
r.set "bar", "s2"
|
28
|
+
r.set "baz", "s3"
|
29
|
+
|
30
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
31
|
+
|
32
|
+
assert_equal 1, r.del(["foo"])
|
33
|
+
|
34
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
35
|
+
|
36
|
+
assert_equal 2, r.del(["bar", "baz"])
|
37
|
+
|
38
|
+
assert_equal [], r.keys("*").sort
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_randomkey
|
42
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
43
|
+
r.randomkey
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_rename
|
48
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
49
|
+
r.set("foo", "s1")
|
50
|
+
r.rename "foo", "bar"
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal "s1", r.get("foo")
|
54
|
+
assert_equal nil, r.get("bar")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_renamenx
|
58
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
59
|
+
r.set("foo", "s1")
|
60
|
+
r.rename "foo", "bar"
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_equal "s1", r.get("foo")
|
64
|
+
assert_equal nil , r.get("bar")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_dbsize
|
68
|
+
assert_equal [0], r.dbsize
|
69
|
+
|
70
|
+
r.set("foo", "s1")
|
71
|
+
|
72
|
+
assert_equal [1], r.dbsize
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_flushdb
|
76
|
+
r.set("foo", "s1")
|
77
|
+
r.set("bar", "s2")
|
78
|
+
|
79
|
+
assert_equal [2], r.dbsize
|
80
|
+
|
81
|
+
r.flushdb
|
82
|
+
|
83
|
+
assert_equal [0], r.dbsize
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_migrate
|
87
|
+
r.set("foo", "s1")
|
88
|
+
|
89
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
90
|
+
r.migrate("foo", {})
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class TestDistributedCommandsRequiringClustering < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include Helper::Distributed
|
6
|
+
|
7
|
+
def test_rename
|
8
|
+
r.set("{qux}foo", "s1")
|
9
|
+
r.rename "{qux}foo", "{qux}bar"
|
10
|
+
|
11
|
+
assert_equal "s1", r.get("{qux}bar")
|
12
|
+
assert_equal nil, r.get("{qux}foo")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_renamenx
|
16
|
+
r.set("{qux}foo", "s1")
|
17
|
+
r.set("{qux}bar", "s2")
|
18
|
+
|
19
|
+
assert_equal false, r.renamenx("{qux}foo", "{qux}bar")
|
20
|
+
|
21
|
+
assert_equal "s1", r.get("{qux}foo")
|
22
|
+
assert_equal "s2", r.get("{qux}bar")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_brpoplpush
|
26
|
+
r.rpush "{qux}foo", "s1"
|
27
|
+
r.rpush "{qux}foo", "s2"
|
28
|
+
|
29
|
+
assert_equal "s2", r.brpoplpush("{qux}foo", "{qux}bar", :timeout => 1)
|
30
|
+
assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_rpoplpush
|
34
|
+
r.rpush "{qux}foo", "s1"
|
35
|
+
r.rpush "{qux}foo", "s2"
|
36
|
+
|
37
|
+
assert_equal "s2", r.rpoplpush("{qux}foo", "{qux}bar")
|
38
|
+
assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
|
39
|
+
assert_equal "s1", r.rpoplpush("{qux}foo", "{qux}bar")
|
40
|
+
assert_equal ["s1", "s2"], r.lrange("{qux}bar", 0, -1)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_smove
|
44
|
+
r.sadd "{qux}foo", "s1"
|
45
|
+
r.sadd "{qux}bar", "s2"
|
46
|
+
|
47
|
+
assert r.smove("{qux}foo", "{qux}bar", "s1")
|
48
|
+
assert r.sismember("{qux}bar", "s1")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_sinter
|
52
|
+
r.sadd "{qux}foo", "s1"
|
53
|
+
r.sadd "{qux}foo", "s2"
|
54
|
+
r.sadd "{qux}bar", "s2"
|
55
|
+
|
56
|
+
assert_equal ["s2"], r.sinter("{qux}foo", "{qux}bar")
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_sinterstore
|
60
|
+
r.sadd "{qux}foo", "s1"
|
61
|
+
r.sadd "{qux}foo", "s2"
|
62
|
+
r.sadd "{qux}bar", "s2"
|
63
|
+
|
64
|
+
r.sinterstore("{qux}baz", "{qux}foo", "{qux}bar")
|
65
|
+
|
66
|
+
assert_equal ["s2"], r.smembers("{qux}baz")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_sunion
|
70
|
+
r.sadd "{qux}foo", "s1"
|
71
|
+
r.sadd "{qux}foo", "s2"
|
72
|
+
r.sadd "{qux}bar", "s2"
|
73
|
+
r.sadd "{qux}bar", "s3"
|
74
|
+
|
75
|
+
assert_equal ["s1", "s2", "s3"], r.sunion("{qux}foo", "{qux}bar").sort
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_sunionstore
|
79
|
+
r.sadd "{qux}foo", "s1"
|
80
|
+
r.sadd "{qux}foo", "s2"
|
81
|
+
r.sadd "{qux}bar", "s2"
|
82
|
+
r.sadd "{qux}bar", "s3"
|
83
|
+
|
84
|
+
r.sunionstore("{qux}baz", "{qux}foo", "{qux}bar")
|
85
|
+
|
86
|
+
assert_equal ["s1", "s2", "s3"], r.smembers("{qux}baz").sort
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_sdiff
|
90
|
+
r.sadd "{qux}foo", "s1"
|
91
|
+
r.sadd "{qux}foo", "s2"
|
92
|
+
r.sadd "{qux}bar", "s2"
|
93
|
+
r.sadd "{qux}bar", "s3"
|
94
|
+
|
95
|
+
assert_equal ["s1"], r.sdiff("{qux}foo", "{qux}bar")
|
96
|
+
assert_equal ["s3"], r.sdiff("{qux}bar", "{qux}foo")
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_sdiffstore
|
100
|
+
r.sadd "{qux}foo", "s1"
|
101
|
+
r.sadd "{qux}foo", "s2"
|
102
|
+
r.sadd "{qux}bar", "s2"
|
103
|
+
r.sadd "{qux}bar", "s3"
|
104
|
+
|
105
|
+
r.sdiffstore("{qux}baz", "{qux}foo", "{qux}bar")
|
106
|
+
|
107
|
+
assert_equal ["s1"], r.smembers("{qux}baz")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_sort
|
111
|
+
r.set("{qux}foo:1", "s1")
|
112
|
+
r.set("{qux}foo:2", "s2")
|
113
|
+
|
114
|
+
r.rpush("{qux}bar", "1")
|
115
|
+
r.rpush("{qux}bar", "2")
|
116
|
+
|
117
|
+
assert_equal ["s1"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1])
|
118
|
+
assert_equal ["s2"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1], :order => "desc alpha")
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_sort_with_an_array_of_gets
|
122
|
+
r.set("{qux}foo:1:a", "s1a")
|
123
|
+
r.set("{qux}foo:1:b", "s1b")
|
124
|
+
|
125
|
+
r.set("{qux}foo:2:a", "s2a")
|
126
|
+
r.set("{qux}foo:2:b", "s2b")
|
127
|
+
|
128
|
+
r.rpush("{qux}bar", "1")
|
129
|
+
r.rpush("{qux}bar", "2")
|
130
|
+
|
131
|
+
assert_equal [["s1a", "s1b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1])
|
132
|
+
assert_equal [["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1], :order => "desc alpha")
|
133
|
+
assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"])
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_sort_with_store
|
137
|
+
r.set("{qux}foo:1", "s1")
|
138
|
+
r.set("{qux}foo:2", "s2")
|
139
|
+
|
140
|
+
r.rpush("{qux}bar", "1")
|
141
|
+
r.rpush("{qux}bar", "2")
|
142
|
+
|
143
|
+
r.sort("{qux}bar", :get => "{qux}foo:*", :store => "{qux}baz")
|
144
|
+
assert_equal ["s1", "s2"], r.lrange("{qux}baz", 0, -1)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_bitop
|
148
|
+
target_version "2.5.10" do
|
149
|
+
r.set("{qux}foo", "a")
|
150
|
+
r.set("{qux}bar", "b")
|
151
|
+
|
152
|
+
r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
|
153
|
+
assert_equal "\x60", r.get("{qux}foo&bar")
|
154
|
+
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
|
155
|
+
assert_equal "\x63", r.get("{qux}foo|bar")
|
156
|
+
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
|
157
|
+
assert_equal "\x03", r.get("{qux}foo^bar")
|
158
|
+
r.bitop(:not, "{qux}~foo", "{qux}foo")
|
159
|
+
assert_equal "\x9E", r.get("{qux}~foo")
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class TestDistributedConnectionHandling < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include Helper::Distributed
|
6
|
+
|
7
|
+
def test_ping
|
8
|
+
assert_equal ["PONG"], r.ping
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_select
|
12
|
+
r.set "foo", "bar"
|
13
|
+
|
14
|
+
r.select 14
|
15
|
+
assert_equal nil, r.get("foo")
|
16
|
+
|
17
|
+
r.select 15
|
18
|
+
|
19
|
+
assert_equal "bar", r.get("foo")
|
20
|
+
end
|
21
|
+
end
|