redis 4.1.0.beta1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +45 -0
  4. data/lib/redis.rb +497 -20
  5. data/lib/redis/client.rb +14 -6
  6. data/lib/redis/cluster.rb +1 -0
  7. data/lib/redis/cluster/command_loader.rb +2 -0
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +1 -0
  10. data/lib/redis/cluster/slot_loader.rb +2 -0
  11. data/lib/redis/distributed.rb +3 -4
  12. data/lib/redis/version.rb +1 -1
  13. metadata +20 -243
  14. data/.gitignore +0 -19
  15. data/.travis.yml +0 -61
  16. data/.travis/Gemfile +0 -18
  17. data/.yardopts +0 -3
  18. data/Gemfile +0 -8
  19. data/benchmarking/logging.rb +0 -71
  20. data/benchmarking/pipeline.rb +0 -51
  21. data/benchmarking/speed.rb +0 -21
  22. data/benchmarking/suite.rb +0 -24
  23. data/benchmarking/worker.rb +0 -71
  24. data/bin/build +0 -71
  25. data/bors.toml +0 -14
  26. data/examples/basic.rb +0 -15
  27. data/examples/consistency.rb +0 -114
  28. data/examples/dist_redis.rb +0 -43
  29. data/examples/incr-decr.rb +0 -17
  30. data/examples/list.rb +0 -26
  31. data/examples/pubsub.rb +0 -37
  32. data/examples/sentinel.rb +0 -41
  33. data/examples/sentinel/start +0 -49
  34. data/examples/sets.rb +0 -36
  35. data/examples/unicorn/config.ru +0 -3
  36. data/examples/unicorn/unicorn.rb +0 -20
  37. data/makefile +0 -74
  38. data/redis.gemspec +0 -42
  39. data/test/bitpos_test.rb +0 -63
  40. data/test/blocking_commands_test.rb +0 -40
  41. data/test/client_test.rb +0 -76
  42. data/test/cluster_abnormal_state_test.rb +0 -38
  43. data/test/cluster_blocking_commands_test.rb +0 -15
  44. data/test/cluster_client_internals_test.rb +0 -77
  45. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  46. data/test/cluster_client_options_test.rb +0 -147
  47. data/test/cluster_client_pipelining_test.rb +0 -59
  48. data/test/cluster_client_replicas_test.rb +0 -36
  49. data/test/cluster_client_slots_test.rb +0 -94
  50. data/test/cluster_client_transactions_test.rb +0 -71
  51. data/test/cluster_commands_on_cluster_test.rb +0 -165
  52. data/test/cluster_commands_on_connection_test.rb +0 -40
  53. data/test/cluster_commands_on_geo_test.rb +0 -74
  54. data/test/cluster_commands_on_hashes_test.rb +0 -11
  55. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  56. data/test/cluster_commands_on_keys_test.rb +0 -134
  57. data/test/cluster_commands_on_lists_test.rb +0 -15
  58. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  59. data/test/cluster_commands_on_scripting_test.rb +0 -56
  60. data/test/cluster_commands_on_server_test.rb +0 -221
  61. data/test/cluster_commands_on_sets_test.rb +0 -39
  62. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  63. data/test/cluster_commands_on_streams_test.rb +0 -196
  64. data/test/cluster_commands_on_strings_test.rb +0 -15
  65. data/test/cluster_commands_on_transactions_test.rb +0 -41
  66. data/test/cluster_commands_on_value_types_test.rb +0 -14
  67. data/test/command_map_test.rb +0 -28
  68. data/test/commands_on_geo_test.rb +0 -116
  69. data/test/commands_on_hashes_test.rb +0 -7
  70. data/test/commands_on_hyper_log_log_test.rb +0 -7
  71. data/test/commands_on_lists_test.rb +0 -7
  72. data/test/commands_on_sets_test.rb +0 -7
  73. data/test/commands_on_sorted_sets_test.rb +0 -7
  74. data/test/commands_on_strings_test.rb +0 -7
  75. data/test/commands_on_value_types_test.rb +0 -207
  76. data/test/connection_handling_test.rb +0 -275
  77. data/test/connection_test.rb +0 -57
  78. data/test/distributed_blocking_commands_test.rb +0 -52
  79. data/test/distributed_commands_on_hashes_test.rb +0 -21
  80. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  81. data/test/distributed_commands_on_lists_test.rb +0 -19
  82. data/test/distributed_commands_on_sets_test.rb +0 -105
  83. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  84. data/test/distributed_commands_on_strings_test.rb +0 -79
  85. data/test/distributed_commands_on_value_types_test.rb +0 -129
  86. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  87. data/test/distributed_connection_handling_test.rb +0 -21
  88. data/test/distributed_internals_test.rb +0 -68
  89. data/test/distributed_key_tags_test.rb +0 -50
  90. data/test/distributed_persistence_control_commands_test.rb +0 -24
  91. data/test/distributed_publish_subscribe_test.rb +0 -90
  92. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  93. data/test/distributed_scripting_test.rb +0 -100
  94. data/test/distributed_sorting_test.rb +0 -18
  95. data/test/distributed_test.rb +0 -56
  96. data/test/distributed_transactions_test.rb +0 -30
  97. data/test/encoding_test.rb +0 -14
  98. data/test/error_replies_test.rb +0 -57
  99. data/test/fork_safety_test.rb +0 -60
  100. data/test/helper.rb +0 -344
  101. data/test/helper_test.rb +0 -22
  102. data/test/internals_test.rb +0 -395
  103. data/test/lint/blocking_commands.rb +0 -174
  104. data/test/lint/hashes.rb +0 -203
  105. data/test/lint/hyper_log_log.rb +0 -74
  106. data/test/lint/lists.rb +0 -159
  107. data/test/lint/sets.rb +0 -282
  108. data/test/lint/sorted_sets.rb +0 -497
  109. data/test/lint/strings.rb +0 -348
  110. data/test/lint/value_types.rb +0 -130
  111. data/test/persistence_control_commands_test.rb +0 -24
  112. data/test/pipelining_commands_test.rb +0 -246
  113. data/test/publish_subscribe_test.rb +0 -280
  114. data/test/remote_server_control_commands_test.rb +0 -175
  115. data/test/scanning_test.rb +0 -407
  116. data/test/scripting_test.rb +0 -76
  117. data/test/sentinel_command_test.rb +0 -78
  118. data/test/sentinel_test.rb +0 -253
  119. data/test/sorting_test.rb +0 -57
  120. data/test/ssl_test.rb +0 -69
  121. data/test/support/cluster/orchestrator.rb +0 -199
  122. data/test/support/connection/hiredis.rb +0 -1
  123. data/test/support/connection/ruby.rb +0 -1
  124. data/test/support/connection/synchrony.rb +0 -17
  125. data/test/support/redis_mock.rb +0 -130
  126. data/test/support/ssl/gen_certs.sh +0 -31
  127. data/test/support/ssl/trusted-ca.crt +0 -25
  128. data/test/support/ssl/trusted-ca.key +0 -27
  129. data/test/support/ssl/trusted-cert.crt +0 -81
  130. data/test/support/ssl/trusted-cert.key +0 -28
  131. data/test/support/ssl/untrusted-ca.crt +0 -26
  132. data/test/support/ssl/untrusted-ca.key +0 -27
  133. data/test/support/ssl/untrusted-cert.crt +0 -82
  134. data/test/support/ssl/untrusted-cert.key +0 -28
  135. data/test/support/wire/synchrony.rb +0 -24
  136. data/test/support/wire/thread.rb +0 -5
  137. data/test/synchrony_driver.rb +0 -85
  138. data/test/test.conf.erb +0 -9
  139. data/test/thread_safety_test.rb +0 -60
  140. data/test/transactions_test.rb +0 -272
  141. data/test/unknown_commands_test.rb +0 -12
  142. data/test/url_param_test.rb +0 -136
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_geo_test.rb
6
- # @see https://redis.io/commands#geo
7
- class TestClusterCommandsOnGeo < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- MIN_REDIS_VERSION = '3.2.0'
11
-
12
- def add_sicily
13
- redis.geoadd('Sicily',
14
- 13.361389, 38.115556, 'Palermo',
15
- 15.087269, 37.502669, 'Catania')
16
- end
17
-
18
- def test_geoadd
19
- target_version(MIN_REDIS_VERSION) do
20
- assert_equal 2, add_sicily
21
- end
22
- end
23
-
24
- def test_geohash
25
- target_version(MIN_REDIS_VERSION) do
26
- add_sicily
27
- assert_equal %w[sqc8b49rny0 sqdtr74hyu0], redis.geohash('Sicily', %w[Palermo Catania])
28
- end
29
- end
30
-
31
- def test_geopos
32
- target_version(MIN_REDIS_VERSION) do
33
- add_sicily
34
- expected = [%w[13.36138933897018433 38.11555639549629859],
35
- %w[15.08726745843887329 37.50266842333162032],
36
- nil]
37
- assert_equal expected, redis.geopos('Sicily', %w[Palermo Catania NonExisting])
38
- end
39
- end
40
-
41
- def test_geodist
42
- target_version(MIN_REDIS_VERSION) do
43
- add_sicily
44
- assert_equal '166274.1516', redis.geodist('Sicily', 'Palermo', 'Catania')
45
- assert_equal '166.2742', redis.geodist('Sicily', 'Palermo', 'Catania', 'km')
46
- assert_equal '103.3182', redis.geodist('Sicily', 'Palermo', 'Catania', 'mi')
47
- end
48
- end
49
-
50
- def test_georadius
51
- target_version(MIN_REDIS_VERSION) do
52
- add_sicily
53
-
54
- expected = [%w[Palermo 190.4424], %w[Catania 56.4413]]
55
- assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST')
56
-
57
- expected = [['Palermo', %w[13.36138933897018433 38.11555639549629859]],
58
- ['Catania', %w[15.08726745843887329 37.50266842333162032]]]
59
- assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHCOORD')
60
-
61
- expected = [['Palermo', '190.4424', %w[13.36138933897018433 38.11555639549629859]],
62
- ['Catania', '56.4413', %w[15.08726745843887329 37.50266842333162032]]]
63
- assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST', 'WITHCOORD')
64
- end
65
- end
66
-
67
- def test_georadiusbymember
68
- target_version(MIN_REDIS_VERSION) do
69
- redis.geoadd('Sicily', 13.583333, 37.316667, 'Agrigento')
70
- add_sicily
71
- assert_equal %w[Agrigento Palermo], redis.georadiusbymember('Sicily', 'Agrigento', 100, 'km')
72
- end
73
- end
74
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
- require_relative 'lint/hashes'
5
-
6
- # ruby -w -Itest test/cluster_commands_on_hashes_test.rb
7
- # @see https://redis.io/commands#hash
8
- class TestClusterCommandsOnHashes < Test::Unit::TestCase
9
- include Helper::Cluster
10
- include Lint::Hashes
11
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
- require_relative 'lint/hyper_log_log'
5
-
6
- # ruby -w -Itest test/cluster_commands_on_hyper_log_log_test.rb
7
- # @see https://redis.io/commands#hyperloglog
8
- class TestClusterCommandsOnHyperLogLog < Test::Unit::TestCase
9
- include Helper::Cluster
10
- include Lint::HyperLogLog
11
-
12
- def test_pfmerge
13
- assert_raise Redis::CommandError do
14
- super
15
- end
16
- end
17
- end
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_keys_test.rb
6
- # @see https://redis.io/commands#generic
7
- class TestClusterCommandsOnKeys < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def set_some_keys
11
- redis.set('key1', 'Hello')
12
- redis.set('key2', 'World')
13
-
14
- redis.set('{key}1', 'Hello')
15
- redis.set('{key}2', 'World')
16
- end
17
-
18
- def test_del
19
- set_some_keys
20
-
21
- assert_raise(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
22
- redis.del('key1', 'key2')
23
- end
24
-
25
- assert_equal 2, redis.del('{key}1', '{key}2')
26
- end
27
-
28
- def test_migrate
29
- redis.set('mykey', 1)
30
-
31
- assert_raise(Redis::CommandError, 'ERR Target instance replied with error: MOVED 14687 127.0.0.1:7002') do
32
- # We cannot move between cluster nodes.
33
- redis.migrate('mykey', host: '127.0.0.1', port: 7000)
34
- end
35
-
36
- redis_cluster_mock(migrate: ->(*_) { '-IOERR error or timeout writing to target instance' }) do |redis|
37
- assert_raise(Redis::CommandError, 'IOERR error or timeout writing to target instance') do
38
- redis.migrate('mykey', host: '127.0.0.1', port: 11211)
39
- end
40
- end
41
-
42
- redis_cluster_mock(migrate: ->(*_) { '+OK' }) do |redis|
43
- assert_equal 'OK', redis.migrate('mykey', host: '127.0.0.1', port: 6379)
44
- end
45
- end
46
-
47
- def test_object
48
- redis.lpush('mylist', 'Hello World')
49
- assert_equal 1, redis.object('refcount', 'mylist')
50
- expected_encoding = version < '3.2.0' ? 'ziplist' : 'quicklist'
51
- assert_equal expected_encoding, redis.object('encoding', 'mylist')
52
- expected_instance_type = RUBY_VERSION < '2.4.0' ? Fixnum : Integer
53
- assert_instance_of expected_instance_type, redis.object('idletime', 'mylist')
54
-
55
- redis.set('foo', 1000)
56
- assert_equal 'int', redis.object('encoding', 'foo')
57
-
58
- redis.set('bar', '1000bar')
59
- assert_equal 'embstr', redis.object('encoding', 'bar')
60
- end
61
-
62
- def test_randomkey
63
- set_some_keys
64
- assert_true redis.randomkey.is_a?(String)
65
- end
66
-
67
- def test_rename
68
- set_some_keys
69
-
70
- assert_raise(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
71
- redis.rename('key1', 'key3')
72
- end
73
-
74
- assert_equal 'OK', redis.rename('{key}1', '{key}3')
75
- end
76
-
77
- def test_renamenx
78
- set_some_keys
79
-
80
- assert_raise(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
81
- redis.renamenx('key1', 'key2')
82
- end
83
-
84
- assert_equal false, redis.renamenx('{key}1', '{key}2')
85
- end
86
-
87
- def test_sort
88
- redis.lpush('mylist', 3)
89
- redis.lpush('mylist', 1)
90
- redis.lpush('mylist', 5)
91
- redis.lpush('mylist', 2)
92
- redis.lpush('mylist', 4)
93
- assert_equal %w[1 2 3 4 5], redis.sort('mylist')
94
- end
95
-
96
- def test_touch
97
- target_version('3.2.1') do
98
- set_some_keys
99
- assert_equal 1, redis.touch('key1')
100
- assert_equal 1, redis.touch('key2')
101
- assert_equal 1, redis.touch('key1', 'key2')
102
- assert_equal 2, redis.touch('{key}1', '{key}2')
103
- end
104
- end
105
-
106
- def test_unlink
107
- target_version('4.0.0') do
108
- set_some_keys
109
- assert_raise(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
110
- redis.unlink('key1', 'key2', 'key3')
111
- end
112
- assert_equal 2, redis.unlink('{key}1', '{key}2', '{key}3')
113
- end
114
- end
115
-
116
- def test_wait
117
- set_some_keys
118
- assert_equal 1, redis.wait(1, 0)
119
- end
120
-
121
- def test_scan
122
- set_some_keys
123
-
124
- cursor = 0
125
- all_keys = []
126
- loop do
127
- cursor, keys = redis.scan(cursor, match: '{key}*')
128
- all_keys += keys
129
- break if cursor == '0'
130
- end
131
-
132
- assert_equal 2, all_keys.uniq.size
133
- end
134
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
- require_relative 'lint/lists'
5
-
6
- # ruby -w -Itest test/cluster_commands_on_lists_test.rb
7
- # @see https://redis.io/commands#list
8
- class TestClusterCommandsOnLists < Test::Unit::TestCase
9
- include Helper::Cluster
10
- include Lint::Lists
11
-
12
- def test_rpoplpush
13
- assert_raise(Redis::CommandError) { super }
14
- end
15
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_pub_sub_test.rb
6
- # @see https://redis.io/commands#pubsub
7
- class TestClusterCommandsOnPubSub < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def test_publish_subscribe_unsubscribe_pubsub
11
- sub_cnt = 0
12
- messages = {}
13
-
14
- wire = Wire.new do
15
- redis.subscribe('channel1', 'channel2') do |on|
16
- on.subscribe { |_c, t| sub_cnt = t }
17
- on.unsubscribe { |_c, t| sub_cnt = t }
18
- on.message do |c, msg|
19
- messages[c] = msg
20
- # FIXME: blocking occurs when `unsubscribe` method was called with channel arguments
21
- redis.unsubscribe if messages.size == 2
22
- end
23
- end
24
- end
25
-
26
- Wire.pass until sub_cnt == 2
27
-
28
- publisher = build_another_client
29
-
30
- assert_equal %w[channel1 channel2], publisher.pubsub(:channels)
31
- assert_equal %w[channel1 channel2], publisher.pubsub(:channels, 'cha*')
32
- assert_equal [], publisher.pubsub(:channels, 'chachacha*')
33
- assert_equal({}, publisher.pubsub(:numsub))
34
- assert_equal({ 'channel1' => 1, 'channel2' => 1, 'channel3' => 0 },
35
- publisher.pubsub(:numsub, 'channel1', 'channel2', 'channel3'))
36
- assert_equal 0, publisher.pubsub(:numpat)
37
-
38
- publisher.publish('channel1', 'one')
39
- publisher.publish('channel2', 'two')
40
-
41
- wire.join
42
-
43
- assert_equal({ 'channel1' => 'one', 'channel2' => 'two' }, messages.sort.to_h)
44
-
45
- assert_equal [], publisher.pubsub(:channels)
46
- assert_equal [], publisher.pubsub(:channels, 'cha*')
47
- assert_equal [], publisher.pubsub(:channels, 'chachacha*')
48
- assert_equal({}, publisher.pubsub(:numsub))
49
- assert_equal({ 'channel1' => 0, 'channel2' => 0, 'channel3' => 0 },
50
- publisher.pubsub(:numsub, 'channel1', 'channel2', 'channel3'))
51
- assert_equal 0, publisher.pubsub(:numpat)
52
- end
53
-
54
- def test_publish_psubscribe_punsubscribe_pubsub
55
- sub_cnt = 0
56
- messages = {}
57
-
58
- wire = Wire.new do
59
- redis.psubscribe('cha*', 'her*') do |on|
60
- on.psubscribe { |_c, t| sub_cnt = t }
61
- on.punsubscribe { |_c, t| sub_cnt = t }
62
- on.pmessage do |_ptn, chn, msg|
63
- messages[chn] = msg
64
- # FIXME: blocking occurs when `unsubscribe` method was called with channel arguments
65
- redis.punsubscribe if messages.size == 3
66
- end
67
- end
68
- end
69
-
70
- Wire.pass until sub_cnt == 2
71
-
72
- publisher = build_another_client
73
-
74
- assert_equal [], publisher.pubsub(:channels)
75
- assert_equal [], publisher.pubsub(:channels, 'cha*')
76
- assert_equal [], publisher.pubsub(:channels, 'her*')
77
- assert_equal [], publisher.pubsub(:channels, 'guc*')
78
- assert_equal({}, publisher.pubsub(:numsub))
79
- assert_equal({ 'channel1' => 0, 'channel2' => 0, 'hermes3' => 0, 'gucci4' => 0 },
80
- publisher.pubsub(:numsub, 'channel1', 'channel2', 'hermes3', 'gucci4'))
81
- assert_equal 2, publisher.pubsub(:numpat)
82
-
83
- publisher.publish('chanel1', 'one')
84
- publisher.publish('chanel2', 'two')
85
- publisher.publish('hermes3', 'three')
86
- publisher.publish('gucci4', 'four')
87
-
88
- wire.join
89
-
90
- assert_equal({ 'chanel1' => 'one', 'chanel2' => 'two', 'hermes3' => 'three' }, messages.sort.to_h)
91
-
92
- assert_equal [], publisher.pubsub(:channels)
93
- assert_equal [], publisher.pubsub(:channels, 'cha*')
94
- assert_equal [], publisher.pubsub(:channels, 'her*')
95
- assert_equal [], publisher.pubsub(:channels, 'guc*')
96
- assert_equal({}, publisher.pubsub(:numsub))
97
- assert_equal({ 'channel1' => 0, 'channel2' => 0, 'hermes3' => 0, 'gucci4' => 0 },
98
- publisher.pubsub(:numsub, 'channel1', 'channel2', 'hermes3', 'gucci4'))
99
- assert_equal 0, publisher.pubsub(:numpat)
100
- end
101
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_scripting_test.rb
6
- # @see https://redis.io/commands#scripting
7
- class TestClusterCommandsOnScripting < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def test_eval
11
- script = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'
12
- argv = %w[first second]
13
-
14
- keys = %w[key1 key2]
15
- assert_raise(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
16
- redis.eval(script, keys: keys, argv: argv)
17
- end
18
-
19
- keys = %w[{key}1 {key}2]
20
- expected = %w[{key}1 {key}2 first second]
21
- assert_equal expected, redis.eval(script, keys: keys, argv: argv)
22
- end
23
-
24
- def test_evalsha
25
- sha = redis.script(:load, 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}')
26
- expected = %w[{key}1 {key}2 first second]
27
- assert_equal expected, redis.evalsha(sha, keys: %w[{key}1 {key}2], argv: %w[first second])
28
- end
29
-
30
- def test_script_debug
31
- target_version('3.2.0') do
32
- assert_equal 'OK', redis.script(:debug, 'yes')
33
- assert_equal 'OK', redis.script(:debug, 'no')
34
- end
35
- end
36
-
37
- def test_script_exists
38
- sha = redis.script(:load, 'return 1')
39
- assert_equal true, redis.script(:exists, sha)
40
- assert_equal false, redis.script(:exists, 'unknownsha')
41
- end
42
-
43
- def test_script_flush
44
- assert_equal 'OK', redis.script(:flush)
45
- end
46
-
47
- def test_script_kill
48
- redis_cluster_mock(kill: -> { '+OK' }) do |redis|
49
- assert_equal 'OK', redis.script(:kill)
50
- end
51
- end
52
-
53
- def test_script_load
54
- assert_equal 'e0e1f9fabfc9d4800c877a703b823ac0578ff8db', redis.script(:load, 'return 1')
55
- end
56
- end
@@ -1,221 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_server_test.rb
6
- # @see https://redis.io/commands#server
7
- class TestClusterCommandsOnServer < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def test_bgrewriteaof
11
- assert_equal 'Background append only file rewriting started', redis.bgrewriteaof
12
- end
13
-
14
- def test_bgsave
15
- redis_cluster_mock(bgsave: ->(*_) { '+OK' }) do |redis|
16
- assert_equal 'OK', redis.bgsave
17
- end
18
-
19
- err_msg = 'ERR An AOF log rewriting in progress: '\
20
- "can't BGSAVE right now. "\
21
- 'Use BGSAVE SCHEDULE in order to schedule a BGSAVE whenever possible.'
22
-
23
- redis_cluster_mock(bgsave: ->(*_) { "-Error #{err_msg}" }) do |redis|
24
- assert_raise(Redis::Cluster::CommandErrorCollection, 'Command error replied on any node') do
25
- redis.bgsave
26
- end
27
- end
28
- end
29
-
30
- def test_client_kill
31
- redis_cluster_mock(client: ->(*_) { '-Error ERR No such client' }) do |redis|
32
- assert_raise(Redis::CommandError, 'ERR No such client') do
33
- redis.client(:kill, '127.0.0.1:6379')
34
- end
35
- end
36
-
37
- redis_cluster_mock(client: ->(*_) { '+OK' }) do |redis|
38
- assert_equal 'OK', redis.client(:kill, '127.0.0.1:6379')
39
- end
40
- end
41
-
42
- def test_client_list
43
- a_client_info = redis.client(:list).first
44
- actual = a_client_info.keys.sort
45
- expected = %w[addr age cmd db events fd flags id idle multi name obl oll omem psub qbuf qbuf-free sub]
46
- assert_equal expected, actual
47
- end
48
-
49
- def test_client_getname
50
- redis.client(:setname, 'my-client-01')
51
- assert_equal 'my-client-01', redis.client(:getname)
52
- end
53
-
54
- def test_client_pause
55
- assert_equal 'OK', redis.client(:pause, 0)
56
- end
57
-
58
- def test_client_reply
59
- target_version('3.2.0') do
60
- assert_equal 'OK', redis.client(:reply, 'ON')
61
- end
62
- end
63
-
64
- def test_client_setname
65
- assert_equal 'OK', redis.client(:setname, 'my-client-01')
66
- end
67
-
68
- def test_command
69
- assert_instance_of Array, redis.command
70
- end
71
-
72
- def test_command_count
73
- assert_true(redis.command(:count) > 0)
74
- end
75
-
76
- def test_command_getkeys
77
- assert_equal %w[a c e], redis.command(:getkeys, :mset, 'a', 'b', 'c', 'd', 'e', 'f')
78
- end
79
-
80
- def test_command_info
81
- expected = [
82
- ['get', 2, %w[readonly fast], 1, 1, 1],
83
- ['set', -3, %w[write denyoom], 1, 1, 1],
84
- ['eval', -3, %w[noscript movablekeys], 0, 0, 0]
85
- ]
86
- assert_equal expected, redis.command(:info, :get, :set, :eval)
87
- end
88
-
89
- def test_config_get
90
- expected_keys = if version < '3.2.0'
91
- %w[hash-max-ziplist-entries list-max-ziplist-entries set-max-intset-entries zset-max-ziplist-entries]
92
- else
93
- %w[hash-max-ziplist-entries set-max-intset-entries zset-max-ziplist-entries]
94
- end
95
-
96
- assert_equal expected_keys, redis.config(:get, '*max-*-entries*').keys.sort
97
- end
98
-
99
- def test_config_rewrite
100
- redis_cluster_mock(config: ->(*_) { '-Error ERR Rewriting config file: Permission denied' }) do |redis|
101
- assert_raise(Redis::Cluster::CommandErrorCollection, 'Command error replied on any node') do
102
- redis.config(:rewrite)
103
- end
104
- end
105
-
106
- redis_cluster_mock(config: ->(*_) { '+OK' }) do |redis|
107
- assert_equal 'OK', redis.config(:rewrite)
108
- end
109
- end
110
-
111
- def test_config_set
112
- assert_equal 'OK', redis.config(:set, 'hash-max-ziplist-entries', 512)
113
- end
114
-
115
- def test_config_resetstat
116
- assert_equal 'OK', redis.config(:resetstat)
117
- end
118
-
119
- def test_config_db_size
120
- 10.times { |i| redis.set("key#{i}", 1) }
121
- assert_equal 10, redis.dbsize
122
- end
123
-
124
- def test_debug_object
125
- # DEBUG OBJECT is a debugging command that should not be used by clients.
126
- end
127
-
128
- def test_debug_segfault
129
- # DEBUG SEGFAULT performs an invalid memory access that crashes Redis.
130
- # It is used to simulate bugs during the development.
131
- end
132
-
133
- def test_flushall
134
- assert_equal 'OK', redis.flushall
135
- end
136
-
137
- def test_flushdb
138
- assert_equal 'OK', redis.flushdb
139
- end
140
-
141
- def test_info
142
- assert_equal({ 'cluster_enabled' => '1' }, redis.info(:cluster))
143
- end
144
-
145
- def test_lastsave
146
- assert_instance_of Array, redis.lastsave
147
- end
148
-
149
- def test_memory_doctor
150
- target_version('4.0.0') do
151
- assert_instance_of String, redis.memory(:doctor)
152
- end
153
- end
154
-
155
- def test_memory_help
156
- target_version('4.0.0') do
157
- assert_instance_of Array, redis.memory(:help)
158
- end
159
- end
160
-
161
- def test_memory_malloc_stats
162
- target_version('4.0.0') do
163
- assert_instance_of String, redis.memory('malloc-stats')
164
- end
165
- end
166
-
167
- def test_memory_purge
168
- target_version('4.0.0') do
169
- assert_equal 'OK', redis.memory(:purge)
170
- end
171
- end
172
-
173
- def test_memory_stats
174
- target_version('4.0.0') do
175
- assert_instance_of Array, redis.memory(:stats)
176
- end
177
- end
178
-
179
- def test_memory_usage
180
- target_version('4.0.0') do
181
- redis.set('key1', 'Hello World')
182
- assert_equal 61, redis.memory(:usage, 'key1')
183
- end
184
- end
185
-
186
- def test_monitor
187
- # Add MONITOR command test
188
- end
189
-
190
- def test_role
191
- assert_equal %w[master master master], redis.role.map(&:first)
192
- end
193
-
194
- def test_save
195
- assert_equal 'OK', redis.save
196
- end
197
-
198
- def test_shutdown
199
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'SHUTDOWN command should be...') do
200
- redis.shutdown
201
- end
202
- end
203
-
204
- def test_slaveof
205
- assert_raise(Redis::CommandError, 'ERR SLAVEOF not allowed in cluster mode.') do
206
- redis.slaveof(:no, :one)
207
- end
208
- end
209
-
210
- def test_slowlog
211
- assert_instance_of Array, redis.slowlog(:get, 1)
212
- end
213
-
214
- def test_sync
215
- # Internal command used for replication
216
- end
217
-
218
- def test_time
219
- assert_instance_of Array, redis.time
220
- end
221
- end