redis 3.3.5 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis/Gemfile +8 -1
- data/.travis.yml +34 -62
- data/CHANGELOG.md +45 -2
- data/Gemfile +5 -1
- data/README.md +32 -76
- data/benchmarking/logging.rb +1 -1
- data/bin/build +71 -0
- data/bors.toml +14 -0
- data/lib/redis/client.rb +38 -20
- 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/cluster.rb +285 -0
- data/lib/redis/connection/command_helper.rb +2 -8
- data/lib/redis/connection/hiredis.rb +2 -2
- data/lib/redis/connection/ruby.rb +13 -30
- data/lib/redis/connection/synchrony.rb +12 -4
- data/lib/redis/connection.rb +2 -2
- data/lib/redis/distributed.rb +29 -8
- data/lib/redis/errors.rb +46 -0
- data/lib/redis/hash_ring.rb +20 -64
- data/lib/redis/pipeline.rb +9 -7
- data/lib/redis/version.rb +1 -1
- data/lib/redis.rb +287 -52
- data/makefile +74 -0
- data/redis.gemspec +9 -10
- data/test/bitpos_test.rb +13 -19
- data/test/blocking_commands_test.rb +3 -5
- data/test/client_test.rb +18 -1
- 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/command_map_test.rb +3 -5
- data/test/commands_on_geo_test.rb +116 -0
- data/test/commands_on_hashes_test.rb +2 -16
- data/test/commands_on_hyper_log_log_test.rb +3 -17
- data/test/commands_on_lists_test.rb +2 -15
- data/test/commands_on_sets_test.rb +2 -72
- data/test/commands_on_sorted_sets_test.rb +2 -132
- data/test/commands_on_strings_test.rb +2 -96
- data/test/commands_on_value_types_test.rb +80 -6
- data/test/connection_handling_test.rb +5 -7
- data/test/distributed_blocking_commands_test.rb +10 -4
- data/test/distributed_commands_on_hashes_test.rb +16 -5
- data/test/distributed_commands_on_hyper_log_log_test.rb +8 -15
- data/test/distributed_commands_on_lists_test.rb +4 -7
- data/test/distributed_commands_on_sets_test.rb +58 -36
- data/test/distributed_commands_on_sorted_sets_test.rb +51 -10
- data/test/distributed_commands_on_strings_test.rb +30 -10
- data/test/distributed_commands_on_value_types_test.rb +38 -4
- data/test/distributed_commands_requiring_clustering_test.rb +1 -3
- data/test/distributed_connection_handling_test.rb +1 -3
- data/test/distributed_internals_test.rb +8 -19
- data/test/distributed_key_tags_test.rb +4 -6
- data/test/distributed_persistence_control_commands_test.rb +1 -3
- data/test/distributed_publish_subscribe_test.rb +1 -3
- data/test/distributed_remote_server_control_commands_test.rb +1 -3
- data/test/distributed_scripting_test.rb +1 -3
- data/test/distributed_sorting_test.rb +1 -3
- data/test/distributed_test.rb +12 -14
- data/test/distributed_transactions_test.rb +1 -3
- 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 +179 -66
- data/test/helper_test.rb +1 -3
- data/test/internals_test.rb +47 -56
- 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 +108 -20
- data/test/lint/value_types.rb +8 -0
- data/test/persistence_control_commands_test.rb +1 -3
- data/test/pipelining_commands_test.rb +12 -8
- data/test/publish_subscribe_test.rb +1 -3
- data/test/remote_server_control_commands_test.rb +60 -3
- 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/cluster/orchestrator.rb +199 -0
- 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/support/redis_mock.rb +1 -1
- data/test/synchrony_driver.rb +6 -9
- data/test/thread_safety_test.rb +1 -3
- data/test/transactions_test.rb +11 -3
- data/test/unknown_commands_test.rb +1 -3
- data/test/url_param_test.rb +44 -46
- metadata +109 -16
- data/Rakefile +0 -87
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/blocking_commands"
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/blocking_commands"
|
5
3
|
|
6
4
|
class TestDistributedBlockingCommands < Test::Unit::TestCase
|
7
5
|
|
@@ -43,4 +41,12 @@ class TestDistributedBlockingCommands < Test::Unit::TestCase
|
|
43
41
|
r.brpoplpush("foo", "bar", 0)
|
44
42
|
end
|
45
43
|
end
|
44
|
+
|
45
|
+
def test_bzpopmin
|
46
|
+
# Not implemented yet
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_bzpopmax
|
50
|
+
# Not implemented yet
|
51
|
+
end
|
46
52
|
end
|
@@ -1,10 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/hashes"
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/hashes'
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnHashes < Test::Unit::TestCase
|
7
|
-
|
8
5
|
include Helper::Distributed
|
9
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
|
10
21
|
end
|
@@ -1,33 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/hyper_log_log"
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/hyper_log_log'
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnHyperLogLog < Test::Unit::TestCase
|
7
|
-
|
8
5
|
include Helper::Distributed
|
9
6
|
include Lint::HyperLogLog
|
10
7
|
|
11
8
|
def test_pfmerge
|
12
|
-
target_version
|
9
|
+
target_version '2.8.9' do
|
13
10
|
assert_raise Redis::Distributed::CannotDistribute do
|
14
|
-
|
15
|
-
r.pfadd "bar", "s2"
|
16
|
-
|
17
|
-
assert r.pfmerge("res", "foo", "bar")
|
11
|
+
super
|
18
12
|
end
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
22
16
|
def test_pfcount_multiple_keys_diff_nodes
|
23
|
-
target_version
|
17
|
+
target_version '2.8.9' do
|
24
18
|
assert_raise Redis::Distributed::CannotDistribute do
|
25
|
-
r.pfadd
|
26
|
-
r.pfadd
|
19
|
+
r.pfadd 'foo', 's1'
|
20
|
+
r.pfadd 'bar', 's2'
|
27
21
|
|
28
|
-
assert r.pfcount(
|
22
|
+
assert r.pfcount('res', 'foo', 'bar')
|
29
23
|
end
|
30
24
|
end
|
31
25
|
end
|
32
|
-
|
33
26
|
end
|
@@ -1,22 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/lists"
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/lists'
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnLists < Test::Unit::TestCase
|
7
|
-
|
8
5
|
include Helper::Distributed
|
9
6
|
include Lint::Lists
|
10
7
|
|
11
8
|
def test_rpoplpush
|
12
9
|
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
-
r.rpoplpush(
|
10
|
+
r.rpoplpush('foo', 'bar')
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
14
|
def test_brpoplpush
|
18
15
|
assert_raise Redis::Distributed::CannotDistribute do
|
19
|
-
r.brpoplpush(
|
16
|
+
r.brpoplpush('foo', 'bar', timeout: 1)
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
@@ -1,83 +1,105 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/sets"
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/sets'
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnSets < Test::Unit::TestCase
|
7
|
-
|
8
5
|
include Helper::Distributed
|
9
6
|
include Lint::Sets
|
10
7
|
|
11
8
|
def test_smove
|
12
9
|
assert_raise Redis::Distributed::CannotDistribute do
|
13
|
-
r.sadd
|
14
|
-
r.sadd
|
10
|
+
r.sadd 'foo', 's1'
|
11
|
+
r.sadd 'bar', 's2'
|
15
12
|
|
16
|
-
r.smove(
|
13
|
+
r.smove('foo', 'bar', 's1')
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
20
17
|
def test_sinter
|
21
18
|
assert_raise Redis::Distributed::CannotDistribute do
|
22
|
-
r.sadd
|
23
|
-
r.sadd
|
24
|
-
r.sadd
|
19
|
+
r.sadd 'foo', 's1'
|
20
|
+
r.sadd 'foo', 's2'
|
21
|
+
r.sadd 'bar', 's2'
|
25
22
|
|
26
|
-
r.sinter(
|
23
|
+
r.sinter('foo', 'bar')
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
27
|
def test_sinterstore
|
31
28
|
assert_raise Redis::Distributed::CannotDistribute do
|
32
|
-
r.sadd
|
33
|
-
r.sadd
|
34
|
-
r.sadd
|
29
|
+
r.sadd 'foo', 's1'
|
30
|
+
r.sadd 'foo', 's2'
|
31
|
+
r.sadd 'bar', 's2'
|
35
32
|
|
36
|
-
r.sinterstore(
|
33
|
+
r.sinterstore('baz', 'foo', 'bar')
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
40
37
|
def test_sunion
|
41
38
|
assert_raise Redis::Distributed::CannotDistribute do
|
42
|
-
r.sadd
|
43
|
-
r.sadd
|
44
|
-
r.sadd
|
45
|
-
r.sadd
|
39
|
+
r.sadd 'foo', 's1'
|
40
|
+
r.sadd 'foo', 's2'
|
41
|
+
r.sadd 'bar', 's2'
|
42
|
+
r.sadd 'bar', 's3'
|
46
43
|
|
47
|
-
r.sunion(
|
44
|
+
r.sunion('foo', 'bar')
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
51
48
|
def test_sunionstore
|
52
49
|
assert_raise Redis::Distributed::CannotDistribute do
|
53
|
-
r.sadd
|
54
|
-
r.sadd
|
55
|
-
r.sadd
|
56
|
-
r.sadd
|
50
|
+
r.sadd 'foo', 's1'
|
51
|
+
r.sadd 'foo', 's2'
|
52
|
+
r.sadd 'bar', 's2'
|
53
|
+
r.sadd 'bar', 's3'
|
57
54
|
|
58
|
-
r.sunionstore(
|
55
|
+
r.sunionstore('baz', 'foo', 'bar')
|
59
56
|
end
|
60
57
|
end
|
61
58
|
|
62
59
|
def test_sdiff
|
63
60
|
assert_raise Redis::Distributed::CannotDistribute do
|
64
|
-
r.sadd
|
65
|
-
r.sadd
|
66
|
-
r.sadd
|
67
|
-
r.sadd
|
61
|
+
r.sadd 'foo', 's1'
|
62
|
+
r.sadd 'foo', 's2'
|
63
|
+
r.sadd 'bar', 's2'
|
64
|
+
r.sadd 'bar', 's3'
|
68
65
|
|
69
|
-
r.sdiff(
|
66
|
+
r.sdiff('foo', 'bar')
|
70
67
|
end
|
71
68
|
end
|
72
69
|
|
73
70
|
def test_sdiffstore
|
74
71
|
assert_raise Redis::Distributed::CannotDistribute do
|
75
|
-
r.sadd
|
76
|
-
r.sadd
|
77
|
-
r.sadd
|
78
|
-
r.sadd
|
72
|
+
r.sadd 'foo', 's1'
|
73
|
+
r.sadd 'foo', 's2'
|
74
|
+
r.sadd 'bar', 's2'
|
75
|
+
r.sadd 'bar', 's3'
|
76
|
+
|
77
|
+
r.sdiffstore('baz', 'foo', 'bar')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_sscan
|
82
|
+
assert_nothing_raised do
|
83
|
+
r.sadd 'foo', 's1'
|
84
|
+
r.sadd 'foo', 's2'
|
85
|
+
r.sadd 'bar', 's2'
|
86
|
+
r.sadd 'bar', 's3'
|
87
|
+
|
88
|
+
cursor, vals = r.sscan 'foo', 0
|
89
|
+
assert_equal '0', cursor
|
90
|
+
assert_equal %w[s1 s2], vals.sort
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_sscan_each
|
95
|
+
assert_nothing_raised do
|
96
|
+
r.sadd 'foo', 's1'
|
97
|
+
r.sadd 'foo', 's2'
|
98
|
+
r.sadd 'bar', 's2'
|
99
|
+
r.sadd 'bar', 's3'
|
79
100
|
|
80
|
-
r.
|
101
|
+
vals = r.sscan_each('foo').to_a
|
102
|
+
assert_equal %w[s1 s2], vals.sort
|
81
103
|
end
|
82
104
|
end
|
83
105
|
end
|
@@ -1,18 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/sorted_sets"
|
1
|
+
require_relative 'helper'
|
2
|
+
require_relative 'lint/sorted_sets'
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
|
7
|
-
|
8
5
|
include Helper::Distributed
|
9
6
|
include Lint::SortedSets
|
10
7
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
15
55
|
|
16
|
-
|
56
|
+
def test_zunionstore_with_weights
|
57
|
+
assert_raise(Redis::Distributed::CannotDistribute) { super }
|
17
58
|
end
|
18
59
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/strings"
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/strings"
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
7
5
|
|
@@ -9,15 +7,27 @@ class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
|
9
7
|
include Lint::Strings
|
10
8
|
|
11
9
|
def test_mget
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
end
|
16
16
|
|
17
17
|
def test_mget_mapped
|
18
|
-
|
19
|
-
|
20
|
-
|
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"]
|
21
31
|
end
|
22
32
|
|
23
33
|
def test_mset
|
@@ -56,4 +66,14 @@ class TestDistributedCommandsOnStrings < Test::Unit::TestCase
|
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
69
|
+
|
70
|
+
def test_mapped_mget_in_a_pipeline_returns_hash
|
71
|
+
assert_raise Redis::Distributed::CannotDistribute do
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_bitfield
|
77
|
+
# Not implemented yet
|
78
|
+
end
|
59
79
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/value_types"
|
1
|
+
require_relative "helper"
|
2
|
+
require_relative "lint/value_types"
|
5
3
|
|
6
4
|
class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
|
7
5
|
|
@@ -40,6 +38,42 @@ class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
|
|
40
38
|
assert_equal [], r.keys("*").sort
|
41
39
|
end
|
42
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
|
+
|
43
77
|
def test_randomkey
|
44
78
|
assert_raise Redis::Distributed::CannotDistribute do
|
45
79
|
r.randomkey
|
@@ -1,41 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestDistributedInternals < Test::Unit::TestCase
|
6
4
|
|
7
5
|
include Helper::Distributed
|
8
6
|
|
9
7
|
def test_provides_a_meaningful_inspect
|
10
|
-
nodes = ["redis://
|
8
|
+
nodes = ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
11
9
|
redis = Redis::Distributed.new nodes
|
12
10
|
|
13
11
|
assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
|
14
12
|
end
|
15
13
|
|
16
14
|
def test_default_as_urls
|
17
|
-
nodes = ["redis://
|
15
|
+
nodes = ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
18
16
|
redis = Redis::Distributed.new nodes
|
19
|
-
assert_equal ["redis://
|
17
|
+
assert_equal ["redis://127.0.0.1:#{PORT}/15", *NODES], redis.nodes.map { |node| node._client.id }
|
20
18
|
end
|
21
19
|
|
22
20
|
def test_default_as_config_hashes
|
23
21
|
nodes = [OPTIONS.merge(:host => '127.0.0.1'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
|
24
22
|
redis = Redis::Distributed.new nodes
|
25
|
-
assert_equal ["redis://127.0.0.1:#{PORT}/15","redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node.
|
23
|
+
assert_equal ["redis://127.0.0.1:#{PORT}/15","redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node._client.id }
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_as_mix_and_match
|
29
27
|
nodes = ["redis://127.0.0.1:7389/15", OPTIONS.merge(:host => 'somehost'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
|
30
28
|
redis = Redis::Distributed.new nodes
|
31
|
-
assert_equal ["redis://127.0.0.1:7389/15", "redis://somehost:#{PORT}/15", "redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node.
|
29
|
+
assert_equal ["redis://127.0.0.1:7389/15", "redis://somehost:#{PORT}/15", "redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node._client.id }
|
32
30
|
end
|
33
31
|
|
34
32
|
def test_override_id
|
35
33
|
nodes = [OPTIONS.merge(:host => '127.0.0.1', :id => "test"), OPTIONS.merge( :host => 'somehost', :port => PORT.next, :id => "test1")]
|
36
34
|
redis = Redis::Distributed.new nodes
|
37
|
-
assert_equal redis.nodes.first.
|
38
|
-
assert_equal redis.nodes.last.
|
35
|
+
assert_equal redis.nodes.first._client.id, "test"
|
36
|
+
assert_equal redis.nodes.last._client.id, "test1"
|
39
37
|
assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
|
40
38
|
end
|
41
39
|
|
@@ -67,13 +65,4 @@ class TestDistributedInternals < Test::Unit::TestCase
|
|
67
65
|
|
68
66
|
assert_equal [], r2.sinter("baz:foo", "baz:bar")
|
69
67
|
end
|
70
|
-
|
71
|
-
def test_colliding_node_ids
|
72
|
-
nodes = ["redis://localhost:#{PORT}/15", "redis://localhost:#{PORT}/15", *NODES]
|
73
|
-
|
74
|
-
assert_raise(RuntimeError) do
|
75
|
-
Redis::Distributed.new nodes
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
68
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestDistributedKeyTags < Test::Unit::TestCase
|
6
4
|
|
@@ -8,9 +6,9 @@ class TestDistributedKeyTags < Test::Unit::TestCase
|
|
8
6
|
include Helper::Distributed
|
9
7
|
|
10
8
|
def test_hashes_consistently
|
11
|
-
r1 = Redis::Distributed.new ["redis://
|
12
|
-
r2 = Redis::Distributed.new ["redis://
|
13
|
-
r3 = Redis::Distributed.new ["redis://
|
9
|
+
r1 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
10
|
+
r2 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
11
|
+
r3 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
14
12
|
|
15
13
|
assert_equal r1.node_for("foo").id, r2.node_for("foo").id
|
16
14
|
assert_equal r1.node_for("foo").id, r3.node_for("foo").id
|
data/test/distributed_test.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestDistributed < Test::Unit::TestCase
|
6
4
|
|
7
5
|
include Helper::Distributed
|
8
6
|
|
9
7
|
def test_handle_multiple_servers
|
10
|
-
@r = Redis::Distributed.new ["redis://
|
8
|
+
@r = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
|
11
9
|
|
12
10
|
100.times do |idx|
|
13
11
|
@r.set(idx.to_s, "foo#{idx}")
|
@@ -26,19 +24,19 @@ class TestDistributed < Test::Unit::TestCase
|
|
26
24
|
|
27
25
|
@r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
|
28
26
|
|
29
|
-
assert_equal "127.0.0.1", @r.nodes[0].
|
30
|
-
assert_equal PORT, @r.nodes[0].
|
31
|
-
assert_equal 15, @r.nodes[0].
|
32
|
-
assert_equal 10, @r.nodes[0].
|
33
|
-
assert_equal logger, @r.nodes[0].
|
27
|
+
assert_equal "127.0.0.1", @r.nodes[0]._client.host
|
28
|
+
assert_equal PORT, @r.nodes[0]._client.port
|
29
|
+
assert_equal 15, @r.nodes[0]._client.db
|
30
|
+
assert_equal 10, @r.nodes[0]._client.timeout
|
31
|
+
assert_equal logger, @r.nodes[0]._client.logger
|
34
32
|
|
35
33
|
@r.add_node("redis://127.0.0.1:6380/14")
|
36
34
|
|
37
|
-
assert_equal "127.0.0.1", @r.nodes[1].
|
38
|
-
assert_equal 6380, @r.nodes[1].
|
39
|
-
assert_equal 14, @r.nodes[1].
|
40
|
-
assert_equal 10, @r.nodes[1].
|
41
|
-
assert_equal logger, @r.nodes[1].
|
35
|
+
assert_equal "127.0.0.1", @r.nodes[1]._client.host
|
36
|
+
assert_equal 6380, @r.nodes[1]._client.port
|
37
|
+
assert_equal 14, @r.nodes[1]._client.db
|
38
|
+
assert_equal 10, @r.nodes[1]._client.timeout
|
39
|
+
assert_equal logger, @r.nodes[1]._client.logger
|
42
40
|
end
|
43
41
|
|
44
42
|
def test_pipelining_commands_cannot_be_distributed
|