redis 4.0.3 → 4.5.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.
Files changed (157) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +110 -0
  3. data/README.md +126 -17
  4. data/lib/redis/client.rb +130 -82
  5. data/lib/redis/cluster/command_loader.rb +8 -7
  6. data/lib/redis/cluster/node.rb +5 -1
  7. data/lib/redis/cluster/node_key.rb +3 -7
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +31 -14
  10. data/lib/redis/cluster/slot.rb +30 -13
  11. data/lib/redis/cluster/slot_loader.rb +6 -4
  12. data/lib/redis/cluster.rb +23 -17
  13. data/lib/redis/connection/command_helper.rb +5 -2
  14. data/lib/redis/connection/hiredis.rb +4 -3
  15. data/lib/redis/connection/registry.rb +2 -1
  16. data/lib/redis/connection/ruby.rb +139 -106
  17. data/lib/redis/connection/synchrony.rb +9 -4
  18. data/lib/redis/connection.rb +2 -0
  19. data/lib/redis/distributed.rb +171 -70
  20. data/lib/redis/errors.rb +2 -0
  21. data/lib/redis/hash_ring.rb +15 -14
  22. data/lib/redis/pipeline.rb +46 -8
  23. data/lib/redis/subscribe.rb +11 -12
  24. data/lib/redis/version.rb +3 -1
  25. data/lib/redis.rb +1239 -426
  26. metadata +16 -262
  27. data/.gitignore +0 -19
  28. data/.travis/Gemfile +0 -18
  29. data/.travis.yml +0 -61
  30. data/.yardopts +0 -3
  31. data/Gemfile +0 -8
  32. data/benchmarking/logging.rb +0 -71
  33. data/benchmarking/pipeline.rb +0 -51
  34. data/benchmarking/speed.rb +0 -21
  35. data/benchmarking/suite.rb +0 -24
  36. data/benchmarking/worker.rb +0 -71
  37. data/bin/build +0 -71
  38. data/bors.toml +0 -14
  39. data/examples/basic.rb +0 -15
  40. data/examples/consistency.rb +0 -114
  41. data/examples/dist_redis.rb +0 -43
  42. data/examples/incr-decr.rb +0 -17
  43. data/examples/list.rb +0 -26
  44. data/examples/pubsub.rb +0 -37
  45. data/examples/sentinel/sentinel.conf +0 -9
  46. data/examples/sentinel/start +0 -49
  47. data/examples/sentinel.rb +0 -41
  48. data/examples/sets.rb +0 -36
  49. data/examples/unicorn/config.ru +0 -3
  50. data/examples/unicorn/unicorn.rb +0 -20
  51. data/makefile +0 -74
  52. data/redis.gemspec +0 -43
  53. data/test/bitpos_test.rb +0 -63
  54. data/test/blocking_commands_test.rb +0 -40
  55. data/test/client_test.rb +0 -76
  56. data/test/cluster_abnormal_state_test.rb +0 -38
  57. data/test/cluster_blocking_commands_test.rb +0 -15
  58. data/test/cluster_client_internals_test.rb +0 -77
  59. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  60. data/test/cluster_client_options_test.rb +0 -147
  61. data/test/cluster_client_pipelining_test.rb +0 -59
  62. data/test/cluster_client_replicas_test.rb +0 -36
  63. data/test/cluster_client_slots_test.rb +0 -94
  64. data/test/cluster_client_transactions_test.rb +0 -71
  65. data/test/cluster_commands_on_cluster_test.rb +0 -165
  66. data/test/cluster_commands_on_connection_test.rb +0 -40
  67. data/test/cluster_commands_on_geo_test.rb +0 -74
  68. data/test/cluster_commands_on_hashes_test.rb +0 -11
  69. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  70. data/test/cluster_commands_on_keys_test.rb +0 -134
  71. data/test/cluster_commands_on_lists_test.rb +0 -15
  72. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  73. data/test/cluster_commands_on_scripting_test.rb +0 -56
  74. data/test/cluster_commands_on_server_test.rb +0 -221
  75. data/test/cluster_commands_on_sets_test.rb +0 -39
  76. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  77. data/test/cluster_commands_on_streams_test.rb +0 -196
  78. data/test/cluster_commands_on_strings_test.rb +0 -15
  79. data/test/cluster_commands_on_transactions_test.rb +0 -41
  80. data/test/cluster_commands_on_value_types_test.rb +0 -14
  81. data/test/command_map_test.rb +0 -28
  82. data/test/commands_on_geo_test.rb +0 -116
  83. data/test/commands_on_hashes_test.rb +0 -7
  84. data/test/commands_on_hyper_log_log_test.rb +0 -7
  85. data/test/commands_on_lists_test.rb +0 -7
  86. data/test/commands_on_sets_test.rb +0 -7
  87. data/test/commands_on_sorted_sets_test.rb +0 -7
  88. data/test/commands_on_strings_test.rb +0 -7
  89. data/test/commands_on_value_types_test.rb +0 -207
  90. data/test/connection_handling_test.rb +0 -275
  91. data/test/connection_test.rb +0 -57
  92. data/test/db/.gitkeep +0 -0
  93. data/test/distributed_blocking_commands_test.rb +0 -52
  94. data/test/distributed_commands_on_hashes_test.rb +0 -21
  95. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  96. data/test/distributed_commands_on_lists_test.rb +0 -19
  97. data/test/distributed_commands_on_sets_test.rb +0 -105
  98. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  99. data/test/distributed_commands_on_strings_test.rb +0 -79
  100. data/test/distributed_commands_on_value_types_test.rb +0 -129
  101. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  102. data/test/distributed_connection_handling_test.rb +0 -21
  103. data/test/distributed_internals_test.rb +0 -68
  104. data/test/distributed_key_tags_test.rb +0 -50
  105. data/test/distributed_persistence_control_commands_test.rb +0 -24
  106. data/test/distributed_publish_subscribe_test.rb +0 -90
  107. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  108. data/test/distributed_scripting_test.rb +0 -100
  109. data/test/distributed_sorting_test.rb +0 -18
  110. data/test/distributed_test.rb +0 -56
  111. data/test/distributed_transactions_test.rb +0 -30
  112. data/test/encoding_test.rb +0 -14
  113. data/test/error_replies_test.rb +0 -57
  114. data/test/fork_safety_test.rb +0 -60
  115. data/test/helper.rb +0 -345
  116. data/test/helper_test.rb +0 -22
  117. data/test/internals_test.rb +0 -408
  118. data/test/lint/blocking_commands.rb +0 -174
  119. data/test/lint/hashes.rb +0 -203
  120. data/test/lint/hyper_log_log.rb +0 -74
  121. data/test/lint/lists.rb +0 -159
  122. data/test/lint/sets.rb +0 -282
  123. data/test/lint/sorted_sets.rb +0 -497
  124. data/test/lint/strings.rb +0 -348
  125. data/test/lint/value_types.rb +0 -130
  126. data/test/persistence_control_commands_test.rb +0 -24
  127. data/test/pipelining_commands_test.rb +0 -246
  128. data/test/publish_subscribe_test.rb +0 -280
  129. data/test/remote_server_control_commands_test.rb +0 -175
  130. data/test/scanning_test.rb +0 -407
  131. data/test/scripting_test.rb +0 -76
  132. data/test/sentinel_command_test.rb +0 -78
  133. data/test/sentinel_test.rb +0 -253
  134. data/test/sorting_test.rb +0 -57
  135. data/test/ssl_test.rb +0 -69
  136. data/test/support/cluster/orchestrator.rb +0 -199
  137. data/test/support/connection/hiredis.rb +0 -1
  138. data/test/support/connection/ruby.rb +0 -1
  139. data/test/support/connection/synchrony.rb +0 -17
  140. data/test/support/redis_mock.rb +0 -130
  141. data/test/support/ssl/gen_certs.sh +0 -31
  142. data/test/support/ssl/trusted-ca.crt +0 -25
  143. data/test/support/ssl/trusted-ca.key +0 -27
  144. data/test/support/ssl/trusted-cert.crt +0 -81
  145. data/test/support/ssl/trusted-cert.key +0 -28
  146. data/test/support/ssl/untrusted-ca.crt +0 -26
  147. data/test/support/ssl/untrusted-ca.key +0 -27
  148. data/test/support/ssl/untrusted-cert.crt +0 -82
  149. data/test/support/ssl/untrusted-cert.key +0 -28
  150. data/test/support/wire/synchrony.rb +0 -24
  151. data/test/support/wire/thread.rb +0 -5
  152. data/test/synchrony_driver.rb +0 -85
  153. data/test/test.conf.erb +0 -9
  154. data/test/thread_safety_test.rb +0 -60
  155. data/test/transactions_test.rb +0 -272
  156. data/test/unknown_commands_test.rb +0 -12
  157. 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
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_client_pipelining_test.rb
6
- class TestClusterClientPipelining < Test::Unit::TestCase
7
- include Helper::Cluster
8
-
9
- def test_pipelining_with_a_hash_tag
10
- p1 = p2 = p3 = p4 = p5 = p6 = nil
11
-
12
- redis.pipelined do |r|
13
- r.set('{Presidents.of.USA}:1', 'George Washington')
14
- r.set('{Presidents.of.USA}:2', 'John Adams')
15
- r.set('{Presidents.of.USA}:3', 'Thomas Jefferson')
16
- r.set('{Presidents.of.USA}:4', 'James Madison')
17
- r.set('{Presidents.of.USA}:5', 'James Monroe')
18
- r.set('{Presidents.of.USA}:6', 'John Quincy Adams')
19
-
20
- p1 = r.get('{Presidents.of.USA}:1')
21
- p2 = r.get('{Presidents.of.USA}:2')
22
- p3 = r.get('{Presidents.of.USA}:3')
23
- p4 = r.get('{Presidents.of.USA}:4')
24
- p5 = r.get('{Presidents.of.USA}:5')
25
- p6 = r.get('{Presidents.of.USA}:6')
26
- end
27
-
28
- [p1, p2, p3, p4, p5, p6].each do |actual|
29
- assert_true actual.is_a?(Redis::Future)
30
- end
31
-
32
- assert_equal('George Washington', p1.value)
33
- assert_equal('John Adams', p2.value)
34
- assert_equal('Thomas Jefferson', p3.value)
35
- assert_equal('James Madison', p4.value)
36
- assert_equal('James Monroe', p5.value)
37
- assert_equal('John Quincy Adams', p6.value)
38
- end
39
-
40
- def test_pipelining_without_hash_tags
41
- assert_raise(Redis::Cluster::CrossSlotPipeliningError) do
42
- redis.pipelined do
43
- redis.set(:a, 1)
44
- redis.set(:b, 2)
45
- redis.set(:c, 3)
46
- redis.set(:d, 4)
47
- redis.set(:e, 5)
48
- redis.set(:f, 6)
49
-
50
- redis.get(:a)
51
- redis.get(:b)
52
- redis.get(:c)
53
- redis.get(:d)
54
- redis.get(:e)
55
- redis.get(:f)
56
- end
57
- end
58
- end
59
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_client_replicas_test.rb
6
- class TestClusterClientReplicas < Test::Unit::TestCase
7
- include Helper::Cluster
8
-
9
- def test_client_can_command_with_replica
10
- r = build_another_client(replica: true)
11
-
12
- 100.times do |i|
13
- assert_equal 'OK', r.set("key#{i}", i)
14
- end
15
-
16
- 100.times do |i|
17
- assert_equal i.to_s, r.get("key#{i}")
18
- end
19
- end
20
-
21
- def test_client_can_flush_with_replica
22
- r = build_another_client(replica: true)
23
-
24
- assert_equal 'OK', r.flushall
25
- assert_equal 'OK', r.flushdb
26
- end
27
-
28
- def test_some_reference_commands_are_sent_to_slaves_if_needed
29
- r = build_another_client(replica: true)
30
-
31
- 5.times { |i| r.set("key#{i}", i) }
32
-
33
- assert_equal %w[key0 key1 key2 key3 key4], r.keys
34
- assert_equal 5, r.dbsize
35
- end
36
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_client_slots_test.rb
6
- class TestClusterClientSlots < Test::Unit::TestCase
7
- include Helper::Cluster
8
-
9
- def test_slot_class
10
- slot = Redis::Cluster::Slot.new('127.0.0.1:7000' => 1..10)
11
-
12
- assert_equal false, slot.exists?(0)
13
- assert_equal true, slot.exists?(1)
14
- assert_equal true, slot.exists?(10)
15
- assert_equal false, slot.exists?(11)
16
-
17
- assert_equal nil, slot.find_node_key_of_master(0)
18
- assert_equal nil, slot.find_node_key_of_slave(0)
19
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(1)
20
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(1)
21
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(10)
22
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(10)
23
- assert_equal nil, slot.find_node_key_of_master(11)
24
- assert_equal nil, slot.find_node_key_of_slave(11)
25
-
26
- assert_equal nil, slot.put(1, '127.0.0.1:7001')
27
- end
28
-
29
- def test_slot_class_with_node_flags_and_replicas
30
- slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => 1..10, '127.0.0.1:7001' => 1..10 },
31
- { '127.0.0.1:7000' => 'master', '127.0.0.1:7001' => 'slave' },
32
- true)
33
-
34
- assert_equal false, slot.exists?(0)
35
- assert_equal true, slot.exists?(1)
36
- assert_equal true, slot.exists?(10)
37
- assert_equal false, slot.exists?(11)
38
-
39
- assert_equal nil, slot.find_node_key_of_master(0)
40
- assert_equal nil, slot.find_node_key_of_slave(0)
41
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(1)
42
- assert_equal '127.0.0.1:7001', slot.find_node_key_of_slave(1)
43
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(10)
44
- assert_equal '127.0.0.1:7001', slot.find_node_key_of_slave(10)
45
- assert_equal nil, slot.find_node_key_of_master(11)
46
- assert_equal nil, slot.find_node_key_of_slave(11)
47
-
48
- assert_equal nil, slot.put(1, '127.0.0.1:7002')
49
- end
50
-
51
- def test_slot_class_with_node_flags_and_without_replicas
52
- slot = Redis::Cluster::Slot.new({ '127.0.0.1:7000' => 1..10, '127.0.0.1:7001' => 1..10 },
53
- { '127.0.0.1:7000' => 'master', '127.0.0.1:7001' => 'slave' },
54
- false)
55
-
56
- assert_equal false, slot.exists?(0)
57
- assert_equal true, slot.exists?(1)
58
- assert_equal true, slot.exists?(10)
59
- assert_equal false, slot.exists?(11)
60
-
61
- assert_equal nil, slot.find_node_key_of_master(0)
62
- assert_equal nil, slot.find_node_key_of_slave(0)
63
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(1)
64
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(1)
65
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_master(10)
66
- assert_equal '127.0.0.1:7000', slot.find_node_key_of_slave(10)
67
- assert_equal nil, slot.find_node_key_of_master(11)
68
- assert_equal nil, slot.find_node_key_of_slave(11)
69
-
70
- assert_equal nil, slot.put(1, '127.0.0.1:7002')
71
- end
72
-
73
- def test_slot_class_with_empty_slots
74
- slot = Redis::Cluster::Slot.new({})
75
-
76
- assert_equal false, slot.exists?(0)
77
- assert_equal false, slot.exists?(1)
78
-
79
- assert_equal nil, slot.find_node_key_of_master(0)
80
- assert_equal nil, slot.find_node_key_of_slave(0)
81
- assert_equal nil, slot.find_node_key_of_master(1)
82
- assert_equal nil, slot.find_node_key_of_slave(1)
83
-
84
- assert_equal nil, slot.put(1, '127.0.0.1:7001')
85
- end
86
-
87
- def test_redirection_when_slot_is_resharding
88
- 100.times { |i| redis.set("{key}#{i}", i) }
89
-
90
- redis_cluster_resharding(12539, src: '127.0.0.1:7002', dest: '127.0.0.1:7000') do
91
- 100.times { |i| assert_equal i.to_s, redis.get("{key}#{i}") }
92
- end
93
- end
94
- end