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,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_client_transactions_test.rb
6
- class TestClusterClientTransactions < Test::Unit::TestCase
7
- include Helper::Cluster
8
-
9
- def test_transaction_with_hash_tag
10
- rc1 = redis
11
- rc2 = build_another_client
12
-
13
- rc1.multi do |cli|
14
- 100.times { |i| cli.set("{key}#{i}", i) }
15
- end
16
-
17
- 100.times { |i| assert_equal i.to_s, rc1.get("{key}#{i}") }
18
- 100.times { |i| assert_equal i.to_s, rc2.get("{key}#{i}") }
19
- end
20
-
21
- def test_transaction_without_hash_tag
22
- rc1 = redis
23
- rc2 = build_another_client
24
-
25
- assert_raise(Redis::Cluster::CrossSlotPipeliningError) do
26
- rc1.multi do |cli|
27
- 100.times { |i| cli.set("key#{i}", i) }
28
- end
29
- end
30
-
31
- 100.times { |i| assert_equal nil, rc1.get("key#{i}") }
32
- 100.times { |i| assert_equal nil, rc2.get("key#{i}") }
33
- end
34
-
35
- def test_transaction_with_replicas
36
- rc1 = build_another_client(replica: true)
37
- rc2 = build_another_client(replica: true)
38
-
39
- rc1.multi do |cli|
40
- 100.times { |i| cli.set("{key}#{i}", i) }
41
- end
42
-
43
- sleep 0.1
44
-
45
- 100.times { |i| assert_equal i.to_s, rc1.get("{key}#{i}") }
46
- 100.times { |i| assert_equal i.to_s, rc2.get("{key}#{i}") }
47
- end
48
-
49
- def test_transaction_with_watch
50
- rc1 = redis
51
- rc2 = build_another_client
52
-
53
- rc1.set('{key}1', 100)
54
- rc1.watch('{key}1')
55
-
56
- rc2.set('{key}1', 200)
57
- val = rc1.get('{key}1').to_i
58
- val += 1
59
-
60
- rc1.multi do |cli|
61
- cli.set('{key}1', val)
62
- cli.set('{key}2', 300)
63
- end
64
-
65
- assert_equal '200', rc1.get('{key}1')
66
- assert_equal '200', rc2.get('{key}1')
67
-
68
- assert_equal nil, rc1.get('{key}2')
69
- assert_equal nil, rc2.get('{key}2')
70
- end
71
- end
@@ -1,165 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_cluster_test.rb
6
- # @see https://redis.io/commands#cluster
7
- class TestClusterCommandsOnCluster < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def test_cluster_addslots
11
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER ADDSLOTS command should be...') do
12
- redis.cluster(:addslots, 0, 1, 2)
13
- end
14
- end
15
-
16
- def test_cluster_count_failure_reports
17
- assert_raise(Redis::CommandError, 'ERR Unknown node unknown-node-id') do
18
- redis.cluster('count-failure-reports', 'unknown-node-id')
19
- end
20
-
21
- node_id = redis.cluster(:nodes).first.fetch('node_id')
22
- assert_true(redis.cluster('count-failure-reports', node_id) >= 0)
23
- end
24
-
25
- def test_cluster_countkeysinslot
26
- assert_true(redis.cluster(:countkeysinslot, 0) >= 0)
27
- assert_true(redis.cluster(:countkeysinslot, 16383) >= 0)
28
-
29
- assert_raise(Redis::CommandError, 'ERR Invalid slot') do
30
- redis.cluster(:countkeysinslot, -1)
31
- end
32
-
33
- assert_raise(Redis::CommandError, 'ERR Invalid slot') do
34
- redis.cluster(:countkeysinslot, 16384)
35
- end
36
- end
37
-
38
- def test_cluster_delslots
39
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER DELSLOTS command should be...') do
40
- redis.cluster(:delslots, 0, 1, 2)
41
- end
42
- end
43
-
44
- def test_cluster_failover
45
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER FAILOVER command should be...') do
46
- redis.cluster(:failover, 'FORCE')
47
- end
48
- end
49
-
50
- def test_cluster_forget
51
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER FORGET command should be...') do
52
- redis.cluster(:forget, 'unknown-node-id')
53
- end
54
- end
55
-
56
- def test_cluster_getkeysinslot
57
- assert_instance_of Array, redis.cluster(:getkeysinslot, 0, 3)
58
- end
59
-
60
- def test_cluster_info
61
- info = redis.cluster(:info)
62
-
63
- assert_equal '3', info.fetch('cluster_size')
64
- end
65
-
66
- def test_cluster_keyslot
67
- assert_equal Redis::Cluster::KeySlotConverter.convert('hogehoge'), redis.cluster(:keyslot, 'hogehoge')
68
- assert_equal Redis::Cluster::KeySlotConverter.convert('12345'), redis.cluster(:keyslot, '12345')
69
- assert_equal Redis::Cluster::KeySlotConverter.convert('foo'), redis.cluster(:keyslot, 'boo{foo}woo')
70
- assert_equal Redis::Cluster::KeySlotConverter.convert('antirez.is.cool'), redis.cluster(:keyslot, 'antirez.is.cool')
71
- assert_equal Redis::Cluster::KeySlotConverter.convert(''), redis.cluster(:keyslot, '')
72
- end
73
-
74
- def test_cluster_meet
75
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER MEET command should be...') do
76
- redis.cluster(:meet, '127.0.0.1', 11211)
77
- end
78
- end
79
-
80
- def test_cluster_nodes
81
- cluster_nodes = redis.cluster(:nodes)
82
- sample_node = cluster_nodes.first
83
-
84
- assert_equal 6, cluster_nodes.length
85
- assert_equal true, sample_node.key?('node_id')
86
- assert_equal true, sample_node.key?('ip_port')
87
- assert_equal true, sample_node.key?('flags')
88
- assert_equal true, sample_node.key?('master_node_id')
89
- assert_equal true, sample_node.key?('ping_sent')
90
- assert_equal true, sample_node.key?('pong_recv')
91
- assert_equal true, sample_node.key?('config_epoch')
92
- assert_equal true, sample_node.key?('link_state')
93
- assert_equal true, sample_node.key?('slots')
94
- end
95
-
96
- def test_cluster_replicate
97
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER REPLICATE command should be...') do
98
- redis.cluster(:replicate)
99
- end
100
- end
101
-
102
- def test_cluster_reset
103
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER RESET command should be...') do
104
- redis.cluster(:reset)
105
- end
106
- end
107
-
108
- def test_cluster_saveconfig
109
- assert_equal 'OK', redis.cluster(:saveconfig)
110
- end
111
-
112
- def test_cluster_set_config_epoch
113
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER SET-CONFIG-EPOCH command should be...') do
114
- redis.cluster('set-config-epoch')
115
- end
116
- end
117
-
118
- def test_cluster_setslot
119
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'CLUSTER SETSLOT command should be...') do
120
- redis.cluster(:setslot)
121
- end
122
- end
123
-
124
- def test_cluster_slaves
125
- cluster_nodes = redis.cluster(:nodes)
126
-
127
- sample_master_node_id = cluster_nodes.find { |n| n.fetch('master_node_id') == '-' }.fetch('node_id')
128
- sample_slave_node_id = cluster_nodes.find { |n| n.fetch('master_node_id') != '-' }.fetch('node_id')
129
-
130
- assert_equal 'slave', redis.cluster(:slaves, sample_master_node_id).first.fetch('flags').first
131
- assert_raise(Redis::CommandError, 'ERR The specified node is not a master') do
132
- redis.cluster(:slaves, sample_slave_node_id)
133
- end
134
- end
135
-
136
- def test_cluster_slots
137
- slots = redis.cluster(:slots)
138
- sample_slot = slots.first
139
-
140
- assert_equal 3, slots.length
141
- assert_equal true, sample_slot.key?('start_slot')
142
- assert_equal true, sample_slot.key?('end_slot')
143
- assert_equal true, sample_slot.key?('master')
144
- assert_equal true, sample_slot.fetch('master').key?('ip')
145
- assert_equal true, sample_slot.fetch('master').key?('port')
146
- assert_equal true, sample_slot.fetch('master').key?('node_id')
147
- assert_equal true, sample_slot.key?('replicas')
148
- assert_equal true, sample_slot.fetch('replicas').is_a?(Array)
149
- assert_equal true, sample_slot.fetch('replicas').first.key?('ip')
150
- assert_equal true, sample_slot.fetch('replicas').first.key?('port')
151
- assert_equal true, sample_slot.fetch('replicas').first.key?('node_id')
152
- end
153
-
154
- def test_readonly
155
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'READONLY command should be...') do
156
- redis.readonly
157
- end
158
- end
159
-
160
- def test_readwrite
161
- assert_raise(Redis::Cluster::OrchestrationCommandNotSupported, 'READWRITE command should be...') do
162
- redis.readwrite
163
- end
164
- end
165
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'helper'
4
-
5
- # ruby -w -Itest test/cluster_commands_on_connection_test.rb
6
- # @see https://redis.io/commands#connection
7
- class TestClusterCommandsOnConnection < Test::Unit::TestCase
8
- include Helper::Cluster
9
-
10
- def test_auth
11
- redis_cluster_mock(auth: ->(*_) { '+OK' }) do |redis|
12
- assert_equal 'OK', redis.auth('my-password-123')
13
- end
14
- end
15
-
16
- def test_echo
17
- assert_equal 'hogehoge', redis.echo('hogehoge')
18
- end
19
-
20
- def test_ping
21
- assert_equal 'hogehoge', redis.ping('hogehoge')
22
- end
23
-
24
- def test_quit
25
- redis2 = build_another_client
26
- assert_equal 'OK', redis2.quit
27
- end
28
-
29
- def test_select
30
- assert_raise(Redis::CommandError, 'ERR SELECT is not allowed in cluster mode') do
31
- redis.select(1)
32
- end
33
- end
34
-
35
- def test_swapdb
36
- assert_raise(Redis::CommandError, 'ERR SWAPDB is not allowed in cluster mode') do
37
- redis.swapdb(1, 2)
38
- end
39
- end
40
- end
@@ -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