redis 4.1.0.beta1 → 4.1.0
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/CHANGELOG.md +13 -2
- data/README.md +45 -0
- data/lib/redis.rb +497 -20
- data/lib/redis/client.rb +14 -6
- data/lib/redis/cluster.rb +1 -0
- data/lib/redis/cluster/command_loader.rb +2 -0
- data/lib/redis/cluster/node_loader.rb +2 -0
- data/lib/redis/cluster/option.rb +1 -0
- data/lib/redis/cluster/slot_loader.rb +2 -0
- data/lib/redis/distributed.rb +3 -4
- data/lib/redis/version.rb +1 -1
- metadata +20 -243
- data/.gitignore +0 -19
- data/.travis.yml +0 -61
- data/.travis/Gemfile +0 -18
- data/.yardopts +0 -3
- data/Gemfile +0 -8
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/bin/build +0 -71
- data/bors.toml +0 -14
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel.rb +0 -41
- data/examples/sentinel/start +0 -49
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/makefile +0 -74
- data/redis.gemspec +0 -42
- data/test/bitpos_test.rb +0 -63
- data/test/blocking_commands_test.rb +0 -40
- data/test/client_test.rb +0 -76
- data/test/cluster_abnormal_state_test.rb +0 -38
- data/test/cluster_blocking_commands_test.rb +0 -15
- data/test/cluster_client_internals_test.rb +0 -77
- data/test/cluster_client_key_hash_tags_test.rb +0 -88
- data/test/cluster_client_options_test.rb +0 -147
- data/test/cluster_client_pipelining_test.rb +0 -59
- data/test/cluster_client_replicas_test.rb +0 -36
- data/test/cluster_client_slots_test.rb +0 -94
- data/test/cluster_client_transactions_test.rb +0 -71
- data/test/cluster_commands_on_cluster_test.rb +0 -165
- data/test/cluster_commands_on_connection_test.rb +0 -40
- data/test/cluster_commands_on_geo_test.rb +0 -74
- data/test/cluster_commands_on_hashes_test.rb +0 -11
- data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
- data/test/cluster_commands_on_keys_test.rb +0 -134
- data/test/cluster_commands_on_lists_test.rb +0 -15
- data/test/cluster_commands_on_pub_sub_test.rb +0 -101
- data/test/cluster_commands_on_scripting_test.rb +0 -56
- data/test/cluster_commands_on_server_test.rb +0 -221
- data/test/cluster_commands_on_sets_test.rb +0 -39
- data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
- data/test/cluster_commands_on_streams_test.rb +0 -196
- data/test/cluster_commands_on_strings_test.rb +0 -15
- data/test/cluster_commands_on_transactions_test.rb +0 -41
- data/test/cluster_commands_on_value_types_test.rb +0 -14
- data/test/command_map_test.rb +0 -28
- data/test/commands_on_geo_test.rb +0 -116
- data/test/commands_on_hashes_test.rb +0 -7
- data/test/commands_on_hyper_log_log_test.rb +0 -7
- data/test/commands_on_lists_test.rb +0 -7
- data/test/commands_on_sets_test.rb +0 -7
- data/test/commands_on_sorted_sets_test.rb +0 -7
- data/test/commands_on_strings_test.rb +0 -7
- data/test/commands_on_value_types_test.rb +0 -207
- data/test/connection_handling_test.rb +0 -275
- data/test/connection_test.rb +0 -57
- data/test/distributed_blocking_commands_test.rb +0 -52
- data/test/distributed_commands_on_hashes_test.rb +0 -21
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
- data/test/distributed_commands_on_lists_test.rb +0 -19
- data/test/distributed_commands_on_sets_test.rb +0 -105
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
- data/test/distributed_commands_on_strings_test.rb +0 -79
- data/test/distributed_commands_on_value_types_test.rb +0 -129
- data/test/distributed_commands_requiring_clustering_test.rb +0 -162
- data/test/distributed_connection_handling_test.rb +0 -21
- data/test/distributed_internals_test.rb +0 -68
- data/test/distributed_key_tags_test.rb +0 -50
- data/test/distributed_persistence_control_commands_test.rb +0 -24
- data/test/distributed_publish_subscribe_test.rb +0 -90
- data/test/distributed_remote_server_control_commands_test.rb +0 -64
- data/test/distributed_scripting_test.rb +0 -100
- data/test/distributed_sorting_test.rb +0 -18
- data/test/distributed_test.rb +0 -56
- data/test/distributed_transactions_test.rb +0 -30
- data/test/encoding_test.rb +0 -14
- data/test/error_replies_test.rb +0 -57
- data/test/fork_safety_test.rb +0 -60
- data/test/helper.rb +0 -344
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -395
- data/test/lint/blocking_commands.rb +0 -174
- data/test/lint/hashes.rb +0 -203
- data/test/lint/hyper_log_log.rb +0 -74
- data/test/lint/lists.rb +0 -159
- data/test/lint/sets.rb +0 -282
- data/test/lint/sorted_sets.rb +0 -497
- data/test/lint/strings.rb +0 -348
- data/test/lint/value_types.rb +0 -130
- data/test/persistence_control_commands_test.rb +0 -24
- data/test/pipelining_commands_test.rb +0 -246
- data/test/publish_subscribe_test.rb +0 -280
- data/test/remote_server_control_commands_test.rb +0 -175
- data/test/scanning_test.rb +0 -407
- data/test/scripting_test.rb +0 -76
- data/test/sentinel_command_test.rb +0 -78
- data/test/sentinel_test.rb +0 -253
- data/test/sorting_test.rb +0 -57
- data/test/ssl_test.rb +0 -69
- data/test/support/cluster/orchestrator.rb +0 -199
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -85
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -60
- data/test/transactions_test.rb +0 -272
- data/test/unknown_commands_test.rb +0 -12
- data/test/url_param_test.rb +0 -136
@@ -1,40 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
require_relative "lint/blocking_commands"
|
3
|
-
|
4
|
-
class TestBlockingCommands < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Helper::Client
|
7
|
-
include Lint::BlockingCommands
|
8
|
-
|
9
|
-
def assert_takes_longer_than_client_timeout
|
10
|
-
timeout = OPTIONS[:timeout]
|
11
|
-
delay = timeout * 2
|
12
|
-
|
13
|
-
mock(:delay => delay) do |r|
|
14
|
-
t1 = Time.now
|
15
|
-
yield(r)
|
16
|
-
t2 = Time.now
|
17
|
-
|
18
|
-
assert timeout == r._client.timeout
|
19
|
-
assert delay <= (t2 - t1)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_blpop_disable_client_timeout
|
24
|
-
assert_takes_longer_than_client_timeout do |r|
|
25
|
-
assert_equal ["foo", "0"], r.blpop("foo")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_brpop_disable_client_timeout
|
30
|
-
assert_takes_longer_than_client_timeout do |r|
|
31
|
-
assert_equal ["foo", "0"], r.brpop("foo")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_brpoplpush_disable_client_timeout
|
36
|
-
assert_takes_longer_than_client_timeout do |r|
|
37
|
-
assert_equal "0", r.brpoplpush("foo", "bar")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/test/client_test.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestClient < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_call
|
8
|
-
result = r.call("PING")
|
9
|
-
assert_equal result, "PONG"
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_call_with_arguments
|
13
|
-
result = r.call("SET", "foo", "bar")
|
14
|
-
assert_equal result, "OK"
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_call_integers
|
18
|
-
result = r.call("INCR", "foo")
|
19
|
-
assert_equal result, 1
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_call_raise
|
23
|
-
assert_raises(Redis::CommandError) do
|
24
|
-
r.call("INCR")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_queue_commit
|
29
|
-
r.queue("SET", "foo", "bar")
|
30
|
-
r.queue("GET", "foo")
|
31
|
-
result = r.commit
|
32
|
-
|
33
|
-
assert_equal result, ["OK", "bar"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_commit_raise
|
37
|
-
r.queue("SET", "foo", "bar")
|
38
|
-
r.queue("INCR")
|
39
|
-
|
40
|
-
assert_raise(Redis::CommandError) do
|
41
|
-
r.commit
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_queue_after_error
|
46
|
-
r.queue("SET", "foo", "bar")
|
47
|
-
r.queue("INCR")
|
48
|
-
|
49
|
-
assert_raise(Redis::CommandError) do
|
50
|
-
r.commit
|
51
|
-
end
|
52
|
-
|
53
|
-
r.queue("SET", "foo", "bar")
|
54
|
-
r.queue("INCR", "baz")
|
55
|
-
result = r.commit
|
56
|
-
|
57
|
-
assert_equal result, ["OK", 1]
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_client_with_custom_connector
|
61
|
-
custom_connector = Class.new(Redis::Client::Connector) do
|
62
|
-
def resolve
|
63
|
-
@options[:host] = '127.0.0.5'
|
64
|
-
@options[:port] = '999'
|
65
|
-
@options
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
assert_raise_message(
|
70
|
-
'Error connecting to Redis on 127.0.0.5:999 (Errno::ECONNREFUSED)'
|
71
|
-
) do
|
72
|
-
new_redis = _new_client(connector: custom_connector)
|
73
|
-
new_redis.ping
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
# ruby -w -Itest test/cluster_abnormal_state_test.rb
|
6
|
-
class TestClusterAbnormalState < Test::Unit::TestCase
|
7
|
-
include Helper::Cluster
|
8
|
-
|
9
|
-
def test_the_state_of_cluster_down
|
10
|
-
redis_cluster_down do
|
11
|
-
assert_raise(Redis::CommandError, 'CLUSTERDOWN Hash slot not served') do
|
12
|
-
redis.set('key1', 1)
|
13
|
-
end
|
14
|
-
|
15
|
-
assert_equal 'fail', redis.cluster(:info).fetch('cluster_state')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_the_state_of_cluster_failover
|
20
|
-
redis_cluster_failover do
|
21
|
-
100.times do |i|
|
22
|
-
assert_equal 'OK', r.set("key#{i}", i)
|
23
|
-
end
|
24
|
-
|
25
|
-
100.times do |i|
|
26
|
-
assert_equal i.to_s, r.get("key#{i}")
|
27
|
-
end
|
28
|
-
|
29
|
-
assert_equal 'ok', redis.cluster(:info).fetch('cluster_state')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_raising_error_when_nodes_are_not_cluster_mode
|
34
|
-
assert_raise(Redis::CannotConnectError, 'Redis client could not connect to any cluster nodes') do
|
35
|
-
build_another_client(cluster: %W[redis://127.0.0.1:#{PORT}])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
require_relative 'lint/blocking_commands'
|
5
|
-
|
6
|
-
# ruby -w -Itest test/cluster_blocking_commands_test.rb
|
7
|
-
class TestClusterBlockingCommands < Test::Unit::TestCase
|
8
|
-
include Helper::Cluster
|
9
|
-
include Lint::BlockingCommands
|
10
|
-
|
11
|
-
def mock(options = {}, &blk)
|
12
|
-
commands = build_mock_commands(options)
|
13
|
-
redis_cluster_mock(commands, &blk)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
# ruby -w -Itest test/cluster_client_internals_test.rb
|
6
|
-
class TestClusterClientInternals < Test::Unit::TestCase
|
7
|
-
include Helper::Cluster
|
8
|
-
|
9
|
-
def test_handle_multiple_servers
|
10
|
-
100.times { |i| redis.set(i.to_s, "hogehoge#{i}") }
|
11
|
-
100.times { |i| assert_equal "hogehoge#{i}", redis.get(i.to_s) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_info_of_cluster_mode_is_enabled
|
15
|
-
assert_equal '1', redis.info['cluster_enabled']
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_unknown_commands_does_not_work_by_default
|
19
|
-
assert_raise(Redis::CommandError) do
|
20
|
-
redis.not_yet_implemented_command('boo', 'foo')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_with_reconnect
|
25
|
-
assert_equal('Hello World', redis.with_reconnect { 'Hello World' })
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_without_reconnect
|
29
|
-
assert_equal('Hello World', redis.without_reconnect { 'Hello World' })
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_connected?
|
33
|
-
assert_equal true, redis.connected?
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_close
|
37
|
-
assert_equal true, redis.close
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_disconnect!
|
41
|
-
assert_equal true, redis.disconnect!
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_asking
|
45
|
-
assert_equal 'OK', redis.asking
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_id
|
49
|
-
expected = 'redis://127.0.0.1:7000/0 '\
|
50
|
-
'redis://127.0.0.1:7001/0 '\
|
51
|
-
'redis://127.0.0.1:7002/0'
|
52
|
-
assert_equal expected, redis.id
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_inspect
|
56
|
-
expected = "#<Redis client v#{Redis::VERSION} for "\
|
57
|
-
'redis://127.0.0.1:7000/0 '\
|
58
|
-
'redis://127.0.0.1:7001/0 '\
|
59
|
-
'redis://127.0.0.1:7002/0>'
|
60
|
-
|
61
|
-
assert_equal expected, redis.inspect
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_dup
|
65
|
-
assert_instance_of Redis, redis.dup
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_connection
|
69
|
-
expected = [
|
70
|
-
{ host: '127.0.0.1', port: 7000, db: 0, id: 'redis://127.0.0.1:7000/0', location: '127.0.0.1:7000' },
|
71
|
-
{ host: '127.0.0.1', port: 7001, db: 0, id: 'redis://127.0.0.1:7001/0', location: '127.0.0.1:7001' },
|
72
|
-
{ host: '127.0.0.1', port: 7002, db: 0, id: 'redis://127.0.0.1:7002/0', location: '127.0.0.1:7002' }
|
73
|
-
]
|
74
|
-
|
75
|
-
assert_equal expected, redis.connection
|
76
|
-
end
|
77
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
# ruby -w -Itest test/cluster_client_key_hash_tags_test.rb
|
6
|
-
class TestClusterClientKeyHashTags < Test::Unit::TestCase
|
7
|
-
include Helper::Cluster
|
8
|
-
|
9
|
-
def build_described_class
|
10
|
-
option = Redis::Cluster::Option.new(cluster: ['redis://127.0.0.1:7000'])
|
11
|
-
node = Redis::Cluster::Node.new(option.per_node_key)
|
12
|
-
details = Redis::Cluster::CommandLoader.load(node)
|
13
|
-
Redis::Cluster::Command.new(details)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_key_extraction
|
17
|
-
described_class = build_described_class
|
18
|
-
|
19
|
-
assert_equal 'dogs:1', described_class.extract_first_key(%w[get dogs:1])
|
20
|
-
assert_equal 'user1000', described_class.extract_first_key(%w[get {user1000}.following])
|
21
|
-
assert_equal 'user1000', described_class.extract_first_key(%w[get {user1000}.followers])
|
22
|
-
assert_equal 'foo{}{bar}', described_class.extract_first_key(%w[get foo{}{bar}])
|
23
|
-
assert_equal '{bar', described_class.extract_first_key(%w[get foo{{bar}}zap])
|
24
|
-
assert_equal 'bar', described_class.extract_first_key(%w[get foo{bar}{zap}])
|
25
|
-
|
26
|
-
assert_equal '', described_class.extract_first_key([:get, ''])
|
27
|
-
assert_equal '', described_class.extract_first_key([:get, nil])
|
28
|
-
assert_equal '', described_class.extract_first_key([:get])
|
29
|
-
|
30
|
-
assert_equal '', described_class.extract_first_key([:set, '', 1])
|
31
|
-
assert_equal '', described_class.extract_first_key([:set, nil, 1])
|
32
|
-
assert_equal '', described_class.extract_first_key([:set])
|
33
|
-
|
34
|
-
# Keyless commands
|
35
|
-
assert_equal '', described_class.extract_first_key([:auth, 'password'])
|
36
|
-
assert_equal '', described_class.extract_first_key(%i[client kill])
|
37
|
-
assert_equal '', described_class.extract_first_key(%i[cluster addslots])
|
38
|
-
assert_equal '', described_class.extract_first_key(%i[command])
|
39
|
-
assert_equal '', described_class.extract_first_key(%i[command count])
|
40
|
-
assert_equal '', described_class.extract_first_key(%i[config get])
|
41
|
-
assert_equal '', described_class.extract_first_key(%i[debug segfault])
|
42
|
-
assert_equal '', described_class.extract_first_key([:echo, 'Hello World'])
|
43
|
-
assert_equal '', described_class.extract_first_key([:flushall, 'ASYNC'])
|
44
|
-
assert_equal '', described_class.extract_first_key([:flushdb, 'ASYNC'])
|
45
|
-
assert_equal '', described_class.extract_first_key([:info, 'cluster'])
|
46
|
-
assert_equal '', described_class.extract_first_key(%i[memory doctor])
|
47
|
-
assert_equal '', described_class.extract_first_key([:ping, 'Hi'])
|
48
|
-
assert_equal '', described_class.extract_first_key([:psubscribe, 'channel'])
|
49
|
-
assert_equal '', described_class.extract_first_key([:pubsub, 'channels', '*'])
|
50
|
-
assert_equal '', described_class.extract_first_key([:publish, 'channel', 'Hi'])
|
51
|
-
assert_equal '', described_class.extract_first_key([:punsubscribe, 'channel'])
|
52
|
-
assert_equal '', described_class.extract_first_key([:subscribe, 'channel'])
|
53
|
-
assert_equal '', described_class.extract_first_key([:unsubscribe, 'channel'])
|
54
|
-
assert_equal '', described_class.extract_first_key(%w[script exists sha1 sha1])
|
55
|
-
assert_equal '', described_class.extract_first_key([:select, 1])
|
56
|
-
assert_equal '', described_class.extract_first_key([:shutdown, 'SAVE'])
|
57
|
-
assert_equal '', described_class.extract_first_key([:slaveof, '127.0.0.1', 6379])
|
58
|
-
assert_equal '', described_class.extract_first_key([:slowlog, 'get', 2])
|
59
|
-
assert_equal '', described_class.extract_first_key([:swapdb, 0, 1])
|
60
|
-
assert_equal '', described_class.extract_first_key([:wait, 1, 0])
|
61
|
-
|
62
|
-
# 2nd argument is not a key
|
63
|
-
assert_equal 'key1', described_class.extract_first_key([:eval, 'script', 2, 'key1', 'key2', 'first', 'second'])
|
64
|
-
assert_equal '', described_class.extract_first_key([:eval, 'return 0', 0])
|
65
|
-
assert_equal 'key1', described_class.extract_first_key([:evalsha, 'sha1', 2, 'key1', 'key2', 'first', 'second'])
|
66
|
-
assert_equal '', described_class.extract_first_key([:evalsha, 'return 0', 0])
|
67
|
-
assert_equal 'key1', described_class.extract_first_key([:migrate, '127.0.0.1', 6379, 'key1', 0, 5000])
|
68
|
-
assert_equal 'key1', described_class.extract_first_key([:memory, :usage, 'key1'])
|
69
|
-
assert_equal 'key1', described_class.extract_first_key([:object, 'refcount', 'key1'])
|
70
|
-
assert_equal 'mystream', described_class.extract_first_key([:xread, 'COUNT', 2, 'STREAMS', 'mystream', 0])
|
71
|
-
assert_equal 'mystream', described_class.extract_first_key([:xreadgroup, 'GROUP', 'mygroup', 'Bob', 'COUNT', 2, 'STREAMS', 'mystream', '>'])
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_whether_the_command_effect_is_readonly_or_not
|
75
|
-
described_class = build_described_class
|
76
|
-
|
77
|
-
assert_equal true, described_class.should_send_to_master?([:set])
|
78
|
-
assert_equal false, described_class.should_send_to_slave?([:set])
|
79
|
-
|
80
|
-
assert_equal false, described_class.should_send_to_master?([:get])
|
81
|
-
assert_equal true, described_class.should_send_to_slave?([:get])
|
82
|
-
|
83
|
-
target_version('3.2.0') do
|
84
|
-
assert_equal false, described_class.should_send_to_master?([:info])
|
85
|
-
assert_equal false, described_class.should_send_to_slave?([:info])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'helper'
|
4
|
-
|
5
|
-
# ruby -w -Itest test/cluster_client_options_test.rb
|
6
|
-
class TestClusterClientOptions < Test::Unit::TestCase
|
7
|
-
include Helper::Cluster
|
8
|
-
|
9
|
-
def test_option_class
|
10
|
-
option = Redis::Cluster::Option.new(cluster: %w[rediss://127.0.0.1:7000], replica: true)
|
11
|
-
assert_equal({ '127.0.0.1:7000' => { url: 'rediss://127.0.0.1:7000' } }, option.per_node_key)
|
12
|
-
assert_equal true, option.secure?
|
13
|
-
assert_equal true, option.use_replica?
|
14
|
-
|
15
|
-
option = Redis::Cluster::Option.new(cluster: %w[redis://127.0.0.1:7000], replica: false)
|
16
|
-
assert_equal({ '127.0.0.1:7000' => { url: 'redis://127.0.0.1:7000' } }, option.per_node_key)
|
17
|
-
assert_equal false, option.secure?
|
18
|
-
assert_equal false, option.use_replica?
|
19
|
-
|
20
|
-
option = Redis::Cluster::Option.new(cluster: %w[redis://127.0.0.1:7000])
|
21
|
-
assert_equal({ '127.0.0.1:7000' => { url: 'redis://127.0.0.1:7000' } }, option.per_node_key)
|
22
|
-
assert_equal false, option.secure?
|
23
|
-
assert_equal false, option.use_replica?
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_client_accepts_valid_node_configs
|
27
|
-
nodes = ['redis://127.0.0.1:7000',
|
28
|
-
'redis://127.0.0.1:7001',
|
29
|
-
{ host: '127.0.0.1', port: '7002' },
|
30
|
-
{ 'host' => '127.0.0.1', port: 7003 },
|
31
|
-
'redis://127.0.0.1:7004',
|
32
|
-
'redis://127.0.0.1:7005']
|
33
|
-
|
34
|
-
assert_nothing_raised do
|
35
|
-
build_another_client(cluster: nodes)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_client_accepts_valid_options
|
40
|
-
assert_nothing_raised do
|
41
|
-
build_another_client(timeout: 1.0)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_client_ignores_invalid_options
|
46
|
-
assert_nothing_raised do
|
47
|
-
build_another_client(invalid_option: true)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_client_works_even_if_so_many_unavailable_nodes_specified
|
52
|
-
nodes = (6001..7005).map { |port| "redis://127.0.0.1:#{port}" }
|
53
|
-
redis = build_another_client(cluster: nodes)
|
54
|
-
|
55
|
-
assert_equal 'PONG', redis.ping
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_client_does_not_accept_db_specified_url
|
59
|
-
assert_raise(Redis::CannotConnectError, 'Could not connect to any nodes') do
|
60
|
-
build_another_client(cluster: ['redis://127.0.0.1:7000/1/namespace'])
|
61
|
-
end
|
62
|
-
|
63
|
-
assert_raise(Redis::CannotConnectError, 'Could not connect to any nodes') do
|
64
|
-
build_another_client(cluster: [{ host: '127.0.0.1', port: '7000' }], db: 1)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_client_does_not_accept_unconnectable_node_url_only
|
69
|
-
nodes = ['redis://127.0.0.1:7006']
|
70
|
-
|
71
|
-
assert_raise(Redis::CannotConnectError, 'Could not connect to any nodes') do
|
72
|
-
build_another_client(cluster: nodes)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_client_accepts_unconnectable_node_url_included
|
77
|
-
nodes = ['redis://127.0.0.1:7000', 'redis://127.0.0.1:7006']
|
78
|
-
|
79
|
-
assert_nothing_raised(Redis::CannotConnectError, 'Could not connect to any nodes') do
|
80
|
-
build_another_client(cluster: nodes)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_client_does_not_accept_http_scheme_url
|
85
|
-
nodes = ['http://127.0.0.1:80']
|
86
|
-
|
87
|
-
assert_raise(Redis::InvalidClientOptionError, "invalid uri scheme 'http'") do
|
88
|
-
build_another_client(cluster: nodes)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_client_does_not_accept_blank_included_config
|
93
|
-
nodes = ['']
|
94
|
-
|
95
|
-
assert_raise(Redis::InvalidClientOptionError, "invalid uri scheme ''") do
|
96
|
-
build_another_client(cluster: nodes)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_client_does_not_accept_bool_included_config
|
101
|
-
nodes = [true]
|
102
|
-
|
103
|
-
assert_raise(Redis::InvalidClientOptionError, "invalid uri scheme ''") do
|
104
|
-
build_another_client(cluster: nodes)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_client_does_not_accept_nil_included_config
|
109
|
-
nodes = [nil]
|
110
|
-
|
111
|
-
assert_raise(Redis::InvalidClientOptionError, "invalid uri scheme ''") do
|
112
|
-
build_another_client(cluster: nodes)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_client_does_not_accept_array_included_config
|
117
|
-
nodes = [[]]
|
118
|
-
|
119
|
-
assert_raise(Redis::InvalidClientOptionError, "invalid uri scheme ''") do
|
120
|
-
build_another_client(cluster: nodes)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_client_does_not_accept_empty_hash_included_config
|
125
|
-
nodes = [{}]
|
126
|
-
|
127
|
-
assert_raise(Redis::InvalidClientOptionError, 'Redis option of `cluster` must includes `:host` and `:port` keys') do
|
128
|
-
build_another_client(cluster: nodes)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_client_does_not_accept_object_included_config
|
133
|
-
nodes = [Object.new]
|
134
|
-
|
135
|
-
assert_raise(Redis::InvalidClientOptionError, 'Redis Cluster node config must includes String or Hash') do
|
136
|
-
build_another_client(cluster: nodes)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_client_does_not_accept_not_array_config
|
141
|
-
nodes = :not_array
|
142
|
-
|
143
|
-
assert_raise(Redis::InvalidClientOptionError, 'Redis Cluster node config must be Array') do
|
144
|
-
build_another_client(cluster: nodes)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|