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,246 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestPipeliningCommands < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_bulk_commands
8
- r.pipelined do
9
- r.lpush "foo", "s1"
10
- r.lpush "foo", "s2"
11
- end
12
-
13
- assert_equal 2, r.llen("foo")
14
- assert_equal "s2", r.lpop("foo")
15
- assert_equal "s1", r.lpop("foo")
16
- end
17
-
18
- def test_multi_bulk_commands
19
- r.pipelined do
20
- r.mset("foo", "s1", "bar", "s2")
21
- r.mset("baz", "s3", "qux", "s4")
22
- end
23
-
24
- assert_equal "s1", r.get("foo")
25
- assert_equal "s2", r.get("bar")
26
- assert_equal "s3", r.get("baz")
27
- assert_equal "s4", r.get("qux")
28
- end
29
-
30
- def test_bulk_and_multi_bulk_commands_mixed
31
- r.pipelined do
32
- r.lpush "foo", "s1"
33
- r.lpush "foo", "s2"
34
- r.mset("baz", "s3", "qux", "s4")
35
- end
36
-
37
- assert_equal 2, r.llen("foo")
38
- assert_equal "s2", r.lpop("foo")
39
- assert_equal "s1", r.lpop("foo")
40
- assert_equal "s3", r.get("baz")
41
- assert_equal "s4", r.get("qux")
42
- end
43
-
44
- def test_multi_bulk_and_bulk_commands_mixed
45
- r.pipelined do
46
- r.mset("baz", "s3", "qux", "s4")
47
- r.lpush "foo", "s1"
48
- r.lpush "foo", "s2"
49
- end
50
-
51
- assert_equal 2, r.llen("foo")
52
- assert_equal "s2", r.lpop("foo")
53
- assert_equal "s1", r.lpop("foo")
54
- assert_equal "s3", r.get("baz")
55
- assert_equal "s4", r.get("qux")
56
- end
57
-
58
- def test_pipelined_with_an_empty_block
59
- assert_nothing_raised do
60
- r.pipelined do
61
- end
62
- end
63
-
64
- assert_equal 0, r.dbsize
65
- end
66
-
67
- def test_returning_the_result_of_a_pipeline
68
- result = r.pipelined do
69
- r.set "foo", "bar"
70
- r.get "foo"
71
- r.get "bar"
72
- end
73
-
74
- assert_equal ["OK", "bar", nil], result
75
- end
76
-
77
- def test_assignment_of_results_inside_the_block
78
- r.pipelined do
79
- @first = r.sadd("foo", 1)
80
- @second = r.sadd("foo", 1)
81
- end
82
-
83
- assert_equal true, @first.value
84
- assert_equal false, @second.value
85
- end
86
-
87
- # Although we could support accessing the values in these futures,
88
- # it doesn't make a lot of sense.
89
- def test_assignment_of_results_inside_the_block_with_errors
90
- assert_raise(Redis::CommandError) do
91
- r.pipelined do
92
- r.doesnt_exist
93
- @first = r.sadd("foo", 1)
94
- @second = r.sadd("foo", 1)
95
- end
96
- end
97
-
98
- assert_raise(Redis::FutureNotReady) { @first.value }
99
- assert_raise(Redis::FutureNotReady) { @second.value }
100
- end
101
-
102
- def test_assignment_of_results_inside_a_nested_block
103
- r.pipelined do
104
- @first = r.sadd("foo", 1)
105
-
106
- r.pipelined do
107
- @second = r.sadd("foo", 1)
108
- end
109
- end
110
-
111
- assert_equal true, @first.value
112
- assert_equal false, @second.value
113
- end
114
-
115
- def test_futures_raise_when_confused_with_something_else
116
- r.pipelined do
117
- @result = r.sadd("foo", 1)
118
- end
119
-
120
- assert_raise(NoMethodError) { @result.to_s }
121
- end
122
-
123
- def test_futures_raise_when_trying_to_access_their_values_too_early
124
- r.pipelined do
125
- assert_raise(Redis::FutureNotReady) do
126
- r.sadd("foo", 1).value
127
- end
128
- end
129
- end
130
-
131
- def test_futures_raise_when_command_errors_and_needs_transformation
132
- assert_raise(Redis::CommandError) do
133
- r.pipelined do
134
- @result = r.zrange("a", "b", 5, :with_scores => true)
135
- end
136
- end
137
- end
138
-
139
- def test_futures_can_be_identified
140
- r.pipelined do
141
- @result = r.sadd("foo", 1)
142
- end
143
-
144
- assert_equal true, @result.is_a?(Redis::Future)
145
- assert_equal true, @result.is_a?(::BasicObject)
146
- assert_equal Redis::Future, @result.class
147
- end
148
-
149
- def test_returning_the_result_of_an_empty_pipeline
150
- result = r.pipelined do
151
- end
152
-
153
- assert_equal [], result
154
- end
155
-
156
- def test_nesting_pipeline_blocks
157
- r.pipelined do
158
- r.set("foo", "s1")
159
- r.pipelined do
160
- r.set("bar", "s2")
161
- end
162
- end
163
-
164
- assert_equal "s1", r.get("foo")
165
- assert_equal "s2", r.get("bar")
166
- end
167
-
168
- def test_info_in_a_pipeline_returns_hash
169
- result = r.pipelined do
170
- r.info
171
- end
172
-
173
- assert result.first.kind_of?(Hash)
174
- end
175
-
176
- def test_config_get_in_a_pipeline_returns_hash
177
- result = r.pipelined do
178
- r.config(:get, "*")
179
- end
180
-
181
- assert result.first.kind_of?(Hash)
182
- end
183
-
184
- def test_hgetall_in_a_pipeline_returns_hash
185
- r.hmset("hash", "field", "value")
186
- result = r.pipelined do
187
- r.hgetall("hash")
188
- end
189
-
190
- assert_equal result.first, { "field" => "value" }
191
- end
192
-
193
- def test_keys_in_a_pipeline
194
- r.set("key", "value")
195
- result = r.pipelined do
196
- r.keys("*")
197
- end
198
-
199
- assert_equal ["key"], result.first
200
- end
201
-
202
- def test_pipeline_yields_a_connection
203
- r.pipelined do |p|
204
- p.set("foo", "bar")
205
- end
206
-
207
- assert_equal "bar", r.get("foo")
208
- end
209
-
210
- def test_pipeline_select
211
- r.select 1
212
- r.set("db", "1")
213
-
214
- r.pipelined do |p|
215
- p.select 2
216
- p.set("db", "2")
217
- end
218
-
219
- r.select 1
220
- assert_equal "1", r.get("db")
221
-
222
- r.select 2
223
- assert_equal "2", r.get("db")
224
- end
225
-
226
- def test_pipeline_select_client_db
227
- r.select 1
228
- r.pipelined do |p2|
229
- p2.select 2
230
- end
231
-
232
- assert_equal 2, r._client.db
233
- end
234
-
235
- def test_nested_pipeline_select_client_db
236
- r.select 1
237
- r.pipelined do |p2|
238
- p2.select 2
239
- p2.pipelined do |p3|
240
- p3.select 3
241
- end
242
- end
243
-
244
- assert_equal 3, r._client.db
245
- end
246
- end
@@ -1,280 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestPublishSubscribe < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- class TestError < StandardError
8
- end
9
-
10
- def test_subscribe_and_unsubscribe
11
- @subscribed = false
12
- @unsubscribed = false
13
-
14
- wire = Wire.new do
15
- r.subscribe("foo") do |on|
16
- on.subscribe do |channel, total|
17
- @subscribed = true
18
- @t1 = total
19
- end
20
-
21
- on.message do |channel, message|
22
- if message == "s1"
23
- r.unsubscribe
24
- @message = message
25
- end
26
- end
27
-
28
- on.unsubscribe do |channel, total|
29
- @unsubscribed = true
30
- @t2 = total
31
- end
32
- end
33
- end
34
-
35
- # Wait until the subscription is active before publishing
36
- Wire.pass while !@subscribed
37
-
38
- Redis.new(OPTIONS).publish("foo", "s1")
39
-
40
- wire.join
41
-
42
- assert @subscribed
43
- assert_equal 1, @t1
44
- assert @unsubscribed
45
- assert_equal 0, @t2
46
- assert_equal "s1", @message
47
- end
48
-
49
- def test_psubscribe_and_punsubscribe
50
- @subscribed = false
51
- @unsubscribed = false
52
-
53
- wire = Wire.new do
54
- r.psubscribe("f*") do |on|
55
- on.psubscribe do |pattern, total|
56
- @subscribed = true
57
- @t1 = total
58
- end
59
-
60
- on.pmessage do |pattern, channel, message|
61
- if message == "s1"
62
- r.punsubscribe
63
- @message = message
64
- end
65
- end
66
-
67
- on.punsubscribe do |pattern, total|
68
- @unsubscribed = true
69
- @t2 = total
70
- end
71
- end
72
- end
73
-
74
- # Wait until the subscription is active before publishing
75
- Wire.pass while !@subscribed
76
-
77
- Redis.new(OPTIONS).publish("foo", "s1")
78
-
79
- wire.join
80
-
81
- assert @subscribed
82
- assert_equal 1, @t1
83
- assert @unsubscribed
84
- assert_equal 0, @t2
85
- assert_equal "s1", @message
86
- end
87
-
88
- def test_pubsub_with_numpat_subcommand
89
- target_version("2.8.0") do
90
- @subscribed = false
91
- wire = Wire.new do
92
- r.psubscribe("f*") do |on|
93
- on.psubscribe { |channel, total| @subscribed = true }
94
- on.pmessage { |pattern, channel, message| r.punsubscribe }
95
- end
96
- end
97
- Wire.pass while !@subscribed
98
- redis = Redis.new(OPTIONS)
99
- numpat_result = redis.pubsub(:numpat)
100
-
101
- redis.publish("foo", "s1")
102
- wire.join
103
-
104
- assert_equal redis.pubsub(:numpat), 0
105
- assert_equal numpat_result, 1
106
- end
107
- end
108
-
109
-
110
- def test_pubsub_with_channels_and_numsub_subcommnads
111
- target_version("2.8.0") do
112
- @subscribed = false
113
- wire = Wire.new do
114
- r.subscribe("foo") do |on|
115
- on.subscribe { |channel, total| @subscribed = true }
116
- on.message { |channel, message| r.unsubscribe }
117
- end
118
- end
119
- Wire.pass while !@subscribed
120
- redis = Redis.new(OPTIONS)
121
- channels_result = redis.pubsub(:channels)
122
- numsub_result = redis.pubsub(:numsub, 'foo', 'boo')
123
-
124
- redis.publish("foo", "s1")
125
- wire.join
126
-
127
- assert_equal channels_result, ['foo']
128
- assert_equal numsub_result, ['foo', 1, 'boo', 0]
129
- end
130
- end
131
-
132
- def test_subscribe_connection_usable_after_raise
133
- @subscribed = false
134
-
135
- wire = Wire.new do
136
- begin
137
- r.subscribe("foo") do |on|
138
- on.subscribe do |channel, total|
139
- @subscribed = true
140
- end
141
-
142
- on.message do |channel, message|
143
- raise TestError
144
- end
145
- end
146
- rescue TestError
147
- end
148
- end
149
-
150
- # Wait until the subscription is active before publishing
151
- Wire.pass while !@subscribed
152
-
153
- Redis.new(OPTIONS).publish("foo", "s1")
154
-
155
- wire.join
156
-
157
- assert_equal "PONG", r.ping
158
- end
159
-
160
- def test_psubscribe_connection_usable_after_raise
161
- @subscribed = false
162
-
163
- wire = Wire.new do
164
- begin
165
- r.psubscribe("f*") do |on|
166
- on.psubscribe do |pattern, total|
167
- @subscribed = true
168
- end
169
-
170
- on.pmessage do |pattern, channel, message|
171
- raise TestError
172
- end
173
- end
174
- rescue TestError
175
- end
176
- end
177
-
178
- # Wait until the subscription is active before publishing
179
- Wire.pass while !@subscribed
180
-
181
- Redis.new(OPTIONS).publish("foo", "s1")
182
-
183
- wire.join
184
-
185
- assert_equal "PONG", r.ping
186
- end
187
-
188
- def test_subscribe_within_subscribe
189
- @channels = []
190
-
191
- wire = Wire.new do
192
- r.subscribe("foo") do |on|
193
- on.subscribe do |channel, total|
194
- @channels << channel
195
-
196
- r.subscribe("bar") if channel == "foo"
197
- r.unsubscribe if channel == "bar"
198
- end
199
- end
200
- end
201
-
202
- wire.join
203
-
204
- assert_equal ["foo", "bar"], @channels
205
- end
206
-
207
- def test_other_commands_within_a_subscribe
208
- assert_raise Redis::CommandError do
209
- r.subscribe("foo") do |on|
210
- on.subscribe do |channel, total|
211
- r.set("bar", "s2")
212
- end
213
- end
214
- end
215
- end
216
-
217
- def test_subscribe_without_a_block
218
- assert_raise LocalJumpError do
219
- r.subscribe("foo")
220
- end
221
- end
222
-
223
- def test_unsubscribe_without_a_subscribe
224
- assert_raise RuntimeError do
225
- r.unsubscribe
226
- end
227
-
228
- assert_raise RuntimeError do
229
- r.punsubscribe
230
- end
231
- end
232
-
233
- def test_subscribe_past_a_timeout
234
- # For some reason, a thread here doesn't reproduce the issue.
235
- sleep = %{sleep #{OPTIONS[:timeout] * 2}}
236
- publish = %{ruby -rsocket -e 't=TCPSocket.new("127.0.0.1",#{OPTIONS[:port]});t.write("publish foo bar\\r\\n");t.read(4);t.close'}
237
- cmd = [sleep, publish].join("; ")
238
-
239
- IO.popen(cmd, "r+") do |pipe|
240
- received = false
241
-
242
- r.subscribe "foo" do |on|
243
- on.message do |channel, message|
244
- received = true
245
- r.unsubscribe
246
- end
247
- end
248
-
249
- assert received
250
- end
251
- end
252
-
253
- def test_subscribe_with_timeout
254
- received = false
255
-
256
- assert_raise Redis::TimeoutError do
257
- r.subscribe_with_timeout(1, "foo") do |on|
258
- on.message do |channel, message|
259
- received = true
260
- end
261
- end
262
- end
263
-
264
- assert !received
265
- end
266
-
267
- def test_psubscribe_with_timeout
268
- received = false
269
-
270
- assert_raise Redis::TimeoutError do
271
- r.psubscribe_with_timeout(1, "f*") do |on|
272
- on.message do |channel, message|
273
- received = true
274
- end
275
- end
276
- end
277
-
278
- assert !received
279
- end
280
- end
@@ -1,175 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestRemoteServerControlCommands < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_info
8
- keys = [
9
- "redis_version",
10
- "uptime_in_seconds",
11
- "uptime_in_days",
12
- "connected_clients",
13
- "used_memory",
14
- "total_connections_received",
15
- "total_commands_processed",
16
- ]
17
-
18
- info = r.info
19
-
20
- keys.each do |k|
21
- msg = "expected #info to include #{k}"
22
- assert info.keys.include?(k), msg
23
- end
24
- end
25
-
26
- def test_info_commandstats
27
- target_version "2.5.7" do
28
- r.config(:resetstat)
29
- r.ping
30
-
31
- result = r.info(:commandstats)
32
- assert_equal "1", result["ping"]["calls"]
33
- end
34
- end
35
-
36
- def test_monitor_redis_lt_2_5_0
37
- return unless version < "2.5.0"
38
-
39
- log = []
40
-
41
- wire = Wire.new do
42
- Redis.new(OPTIONS).monitor do |line|
43
- log << line
44
- break if log.size == 3
45
- end
46
- end
47
-
48
- Wire.pass while log.empty? # Faster than sleep
49
-
50
- r.set "foo", "s1"
51
-
52
- wire.join
53
-
54
- assert log[-1][%q{(db 15) "set" "foo" "s1"}]
55
- end
56
-
57
- def test_monitor_redis_gte_2_5_0
58
- return unless version >= "2.5.0"
59
-
60
- log = []
61
-
62
- wire = Wire.new do
63
- Redis.new(OPTIONS).monitor do |line|
64
- log << line
65
- break if line =~ /set/
66
- end
67
- end
68
-
69
- Wire.pass while log.empty? # Faster than sleep
70
-
71
- r.set "foo", "s1"
72
-
73
- wire.join
74
-
75
- assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/
76
- end
77
-
78
- def test_monitor_returns_value_for_break
79
- result = r.monitor do |line|
80
- break line
81
- end
82
-
83
- assert_equal "OK", result
84
- end
85
-
86
- def test_echo
87
- assert_equal "foo bar baz\n", r.echo("foo bar baz\n")
88
- end
89
-
90
- def test_debug
91
- r.set "foo", "s1"
92
-
93
- assert r.debug(:object, "foo").kind_of?(String)
94
- end
95
-
96
- def test_object
97
- r.lpush "list", "value"
98
-
99
- assert_equal 1, r.object(:refcount, "list")
100
- encoding = r.object(:encoding, "list")
101
- assert "ziplist" == encoding || "quicklist" == encoding, "Wrong encoding for list"
102
- assert r.object(:idletime, "list").kind_of?(Integer)
103
- end
104
-
105
- def test_sync
106
- redis_mock(:sync => lambda { "+OK" }) do |redis|
107
- assert_equal "OK", redis.sync
108
- end
109
- end
110
-
111
- def test_slowlog
112
- r.slowlog(:reset)
113
- result = r.slowlog(:len)
114
- assert_equal 0, result
115
- end
116
-
117
- def test_client
118
- assert_equal r.instance_variable_get(:@client), r._client
119
- end
120
-
121
- def test_client_list
122
- return if version < "2.4.0"
123
-
124
- keys = [
125
- "addr",
126
- "fd",
127
- "name",
128
- "age",
129
- "idle",
130
- "flags",
131
- "db",
132
- "sub",
133
- "psub",
134
- "multi",
135
- "qbuf",
136
- "qbuf-free",
137
- "obl",
138
- "oll",
139
- "omem",
140
- "events",
141
- "cmd"
142
- ]
143
-
144
- clients = r.client(:list)
145
- clients.each do |client|
146
- keys.each do |k|
147
- msg = "expected #client(:list) to include #{k}"
148
- assert client.keys.include?(k), msg
149
- end
150
- end
151
- end
152
-
153
- def test_client_kill
154
- return if version < "2.6.9"
155
-
156
- r.client(:setname, 'redis-rb')
157
- clients = r.client(:list)
158
- i = clients.index {|client| client['name'] == 'redis-rb'}
159
- assert_equal "OK", r.client(:kill, clients[i]["addr"])
160
-
161
- clients = r.client(:list)
162
- i = clients.index {|client| client['name'] == 'redis-rb'}
163
- assert_equal nil, i
164
- end
165
-
166
- def test_client_getname_and_setname
167
- return if version < "2.6.9"
168
-
169
- assert_equal nil, r.client(:getname)
170
-
171
- r.client(:setname, 'redis-rb')
172
- name = r.client(:getname)
173
- assert_equal 'redis-rb', name
174
- end
175
- end