redis 3.3.3 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +280 -12
  3. data/README.md +141 -147
  4. data/lib/redis/client.rb +77 -539
  5. data/lib/redis/commands/bitmaps.rb +66 -0
  6. data/lib/redis/commands/cluster.rb +28 -0
  7. data/lib/redis/commands/connection.rb +53 -0
  8. data/lib/redis/commands/geo.rb +84 -0
  9. data/lib/redis/commands/hashes.rb +254 -0
  10. data/lib/redis/commands/hyper_log_log.rb +37 -0
  11. data/lib/redis/commands/keys.rb +437 -0
  12. data/lib/redis/commands/lists.rb +285 -0
  13. data/lib/redis/commands/pubsub.rb +54 -0
  14. data/lib/redis/commands/scripting.rb +114 -0
  15. data/lib/redis/commands/server.rb +188 -0
  16. data/lib/redis/commands/sets.rb +214 -0
  17. data/lib/redis/commands/sorted_sets.rb +818 -0
  18. data/lib/redis/commands/streams.rb +384 -0
  19. data/lib/redis/commands/strings.rb +314 -0
  20. data/lib/redis/commands/transactions.rb +115 -0
  21. data/lib/redis/commands.rb +235 -0
  22. data/lib/redis/distributed.rb +300 -108
  23. data/lib/redis/errors.rb +22 -1
  24. data/lib/redis/hash_ring.rb +36 -79
  25. data/lib/redis/pipeline.rb +69 -83
  26. data/lib/redis/subscribe.rb +26 -19
  27. data/lib/redis/version.rb +3 -1
  28. data/lib/redis.rb +113 -2685
  29. metadata +40 -218
  30. data/.gitignore +0 -16
  31. data/.travis/Gemfile +0 -11
  32. data/.travis.yml +0 -89
  33. data/.yardopts +0 -3
  34. data/Gemfile +0 -4
  35. data/Rakefile +0 -87
  36. data/benchmarking/logging.rb +0 -71
  37. data/benchmarking/pipeline.rb +0 -51
  38. data/benchmarking/speed.rb +0 -21
  39. data/benchmarking/suite.rb +0 -24
  40. data/benchmarking/worker.rb +0 -71
  41. data/examples/basic.rb +0 -15
  42. data/examples/consistency.rb +0 -114
  43. data/examples/dist_redis.rb +0 -43
  44. data/examples/incr-decr.rb +0 -17
  45. data/examples/list.rb +0 -26
  46. data/examples/pubsub.rb +0 -37
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sentinel.rb +0 -41
  50. data/examples/sets.rb +0 -36
  51. data/examples/unicorn/config.ru +0 -3
  52. data/examples/unicorn/unicorn.rb +0 -20
  53. data/lib/redis/connection/command_helper.rb +0 -44
  54. data/lib/redis/connection/hiredis.rb +0 -66
  55. data/lib/redis/connection/registry.rb +0 -12
  56. data/lib/redis/connection/ruby.rb +0 -429
  57. data/lib/redis/connection/synchrony.rb +0 -133
  58. data/lib/redis/connection.rb +0 -9
  59. data/redis.gemspec +0 -44
  60. data/test/bitpos_test.rb +0 -69
  61. data/test/blocking_commands_test.rb +0 -42
  62. data/test/client_test.rb +0 -59
  63. data/test/command_map_test.rb +0 -30
  64. data/test/commands_on_hashes_test.rb +0 -21
  65. data/test/commands_on_hyper_log_log_test.rb +0 -21
  66. data/test/commands_on_lists_test.rb +0 -20
  67. data/test/commands_on_sets_test.rb +0 -77
  68. data/test/commands_on_sorted_sets_test.rb +0 -137
  69. data/test/commands_on_strings_test.rb +0 -101
  70. data/test/commands_on_value_types_test.rb +0 -133
  71. data/test/connection_handling_test.rb +0 -277
  72. data/test/db/.gitkeep +0 -0
  73. data/test/distributed_blocking_commands_test.rb +0 -46
  74. data/test/distributed_commands_on_hashes_test.rb +0 -10
  75. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  76. data/test/distributed_commands_on_lists_test.rb +0 -22
  77. data/test/distributed_commands_on_sets_test.rb +0 -83
  78. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  79. data/test/distributed_commands_on_strings_test.rb +0 -59
  80. data/test/distributed_commands_on_value_types_test.rb +0 -95
  81. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  82. data/test/distributed_connection_handling_test.rb +0 -23
  83. data/test/distributed_internals_test.rb +0 -79
  84. data/test/distributed_key_tags_test.rb +0 -52
  85. data/test/distributed_persistence_control_commands_test.rb +0 -26
  86. data/test/distributed_publish_subscribe_test.rb +0 -92
  87. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  88. data/test/distributed_scripting_test.rb +0 -102
  89. data/test/distributed_sorting_test.rb +0 -20
  90. data/test/distributed_test.rb +0 -58
  91. data/test/distributed_transactions_test.rb +0 -32
  92. data/test/encoding_test.rb +0 -18
  93. data/test/error_replies_test.rb +0 -59
  94. data/test/fork_safety_test.rb +0 -65
  95. data/test/helper.rb +0 -232
  96. data/test/helper_test.rb +0 -24
  97. data/test/internals_test.rb +0 -457
  98. data/test/lint/blocking_commands.rb +0 -150
  99. data/test/lint/hashes.rb +0 -162
  100. data/test/lint/hyper_log_log.rb +0 -60
  101. data/test/lint/lists.rb +0 -143
  102. data/test/lint/sets.rb +0 -140
  103. data/test/lint/sorted_sets.rb +0 -316
  104. data/test/lint/strings.rb +0 -260
  105. data/test/lint/value_types.rb +0 -122
  106. data/test/persistence_control_commands_test.rb +0 -26
  107. data/test/pipelining_commands_test.rb +0 -242
  108. data/test/publish_subscribe_test.rb +0 -282
  109. data/test/remote_server_control_commands_test.rb +0 -118
  110. data/test/scanning_test.rb +0 -413
  111. data/test/scripting_test.rb +0 -78
  112. data/test/sentinel_command_test.rb +0 -80
  113. data/test/sentinel_test.rb +0 -255
  114. data/test/sorting_test.rb +0 -59
  115. data/test/ssl_test.rb +0 -73
  116. data/test/support/connection/hiredis.rb +0 -1
  117. data/test/support/connection/ruby.rb +0 -1
  118. data/test/support/connection/synchrony.rb +0 -17
  119. data/test/support/redis_mock.rb +0 -130
  120. data/test/support/ssl/gen_certs.sh +0 -31
  121. data/test/support/ssl/trusted-ca.crt +0 -25
  122. data/test/support/ssl/trusted-ca.key +0 -27
  123. data/test/support/ssl/trusted-cert.crt +0 -81
  124. data/test/support/ssl/trusted-cert.key +0 -28
  125. data/test/support/ssl/untrusted-ca.crt +0 -26
  126. data/test/support/ssl/untrusted-ca.key +0 -27
  127. data/test/support/ssl/untrusted-cert.crt +0 -82
  128. data/test/support/ssl/untrusted-cert.key +0 -28
  129. data/test/support/wire/synchrony.rb +0 -24
  130. data/test/support/wire/thread.rb +0 -5
  131. data/test/synchrony_driver.rb +0 -88
  132. data/test/test.conf.erb +0 -9
  133. data/test/thread_safety_test.rb +0 -62
  134. data/test/transactions_test.rb +0 -264
  135. data/test/unknown_commands_test.rb +0 -14
  136. data/test/url_param_test.rb +0 -138
@@ -1,26 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestPersistenceControlCommands < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_save
10
- redis_mock(:save => lambda { "+SAVE" }) do |redis|
11
- assert_equal "SAVE", redis.save
12
- end
13
- end
14
-
15
- def test_bgsave
16
- redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
17
- assert_equal "BGSAVE", redis.bgsave
18
- end
19
- end
20
-
21
- def test_lastsave
22
- redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
23
- assert_equal "LASTSAVE", redis.lastsave
24
- end
25
- end
26
- end
@@ -1,242 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestPipeliningCommands < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_bulk_commands
10
- r.pipelined do
11
- r.lpush "foo", "s1"
12
- r.lpush "foo", "s2"
13
- end
14
-
15
- assert_equal 2, r.llen("foo")
16
- assert_equal "s2", r.lpop("foo")
17
- assert_equal "s1", r.lpop("foo")
18
- end
19
-
20
- def test_multi_bulk_commands
21
- r.pipelined do
22
- r.mset("foo", "s1", "bar", "s2")
23
- r.mset("baz", "s3", "qux", "s4")
24
- end
25
-
26
- assert_equal "s1", r.get("foo")
27
- assert_equal "s2", r.get("bar")
28
- assert_equal "s3", r.get("baz")
29
- assert_equal "s4", r.get("qux")
30
- end
31
-
32
- def test_bulk_and_multi_bulk_commands_mixed
33
- r.pipelined do
34
- r.lpush "foo", "s1"
35
- r.lpush "foo", "s2"
36
- r.mset("baz", "s3", "qux", "s4")
37
- end
38
-
39
- assert_equal 2, r.llen("foo")
40
- assert_equal "s2", r.lpop("foo")
41
- assert_equal "s1", r.lpop("foo")
42
- assert_equal "s3", r.get("baz")
43
- assert_equal "s4", r.get("qux")
44
- end
45
-
46
- def test_multi_bulk_and_bulk_commands_mixed
47
- r.pipelined do
48
- r.mset("baz", "s3", "qux", "s4")
49
- r.lpush "foo", "s1"
50
- r.lpush "foo", "s2"
51
- end
52
-
53
- assert_equal 2, r.llen("foo")
54
- assert_equal "s2", r.lpop("foo")
55
- assert_equal "s1", r.lpop("foo")
56
- assert_equal "s3", r.get("baz")
57
- assert_equal "s4", r.get("qux")
58
- end
59
-
60
- def test_pipelined_with_an_empty_block
61
- assert_nothing_raised do
62
- r.pipelined do
63
- end
64
- end
65
-
66
- assert_equal 0, r.dbsize
67
- end
68
-
69
- def test_returning_the_result_of_a_pipeline
70
- result = r.pipelined do
71
- r.set "foo", "bar"
72
- r.get "foo"
73
- r.get "bar"
74
- end
75
-
76
- assert_equal ["OK", "bar", nil], result
77
- end
78
-
79
- def test_assignment_of_results_inside_the_block
80
- r.pipelined do
81
- @first = r.sadd("foo", 1)
82
- @second = r.sadd("foo", 1)
83
- end
84
-
85
- assert_equal true, @first.value
86
- assert_equal false, @second.value
87
- end
88
-
89
- # Although we could support accessing the values in these futures,
90
- # it doesn't make a lot of sense.
91
- def test_assignment_of_results_inside_the_block_with_errors
92
- assert_raise(Redis::CommandError) do
93
- r.pipelined do
94
- r.doesnt_exist
95
- @first = r.sadd("foo", 1)
96
- @second = r.sadd("foo", 1)
97
- end
98
- end
99
-
100
- assert_raise(Redis::FutureNotReady) { @first.value }
101
- assert_raise(Redis::FutureNotReady) { @second.value }
102
- end
103
-
104
- def test_assignment_of_results_inside_a_nested_block
105
- r.pipelined do
106
- @first = r.sadd("foo", 1)
107
-
108
- r.pipelined do
109
- @second = r.sadd("foo", 1)
110
- end
111
- end
112
-
113
- assert_equal true, @first.value
114
- assert_equal false, @second.value
115
- end
116
-
117
- def test_futures_raise_when_confused_with_something_else
118
- r.pipelined do
119
- @result = r.sadd("foo", 1)
120
- end
121
-
122
- assert_raise(NoMethodError) { @result.to_s }
123
- end
124
-
125
- def test_futures_raise_when_trying_to_access_their_values_too_early
126
- r.pipelined do
127
- assert_raise(Redis::FutureNotReady) do
128
- r.sadd("foo", 1).value
129
- end
130
- end
131
- end
132
-
133
- def test_futures_can_be_identified
134
- r.pipelined do
135
- @result = r.sadd("foo", 1)
136
- end
137
-
138
- assert_equal true, @result.is_a?(Redis::Future)
139
- if defined?(::BasicObject)
140
- assert_equal true, @result.is_a?(::BasicObject)
141
- end
142
- assert_equal Redis::Future, @result.class
143
- end
144
-
145
- def test_returning_the_result_of_an_empty_pipeline
146
- result = r.pipelined do
147
- end
148
-
149
- assert_equal [], result
150
- end
151
-
152
- def test_nesting_pipeline_blocks
153
- r.pipelined do
154
- r.set("foo", "s1")
155
- r.pipelined do
156
- r.set("bar", "s2")
157
- end
158
- end
159
-
160
- assert_equal "s1", r.get("foo")
161
- assert_equal "s2", r.get("bar")
162
- end
163
-
164
- def test_info_in_a_pipeline_returns_hash
165
- result = r.pipelined do
166
- r.info
167
- end
168
-
169
- assert result.first.kind_of?(Hash)
170
- end
171
-
172
- def test_config_get_in_a_pipeline_returns_hash
173
- result = r.pipelined do
174
- r.config(:get, "*")
175
- end
176
-
177
- assert result.first.kind_of?(Hash)
178
- end
179
-
180
- def test_hgetall_in_a_pipeline_returns_hash
181
- r.hmset("hash", "field", "value")
182
- result = r.pipelined do
183
- r.hgetall("hash")
184
- end
185
-
186
- assert_equal result.first, { "field" => "value" }
187
- end
188
-
189
- def test_keys_in_a_pipeline
190
- r.set("key", "value")
191
- result = r.pipelined do
192
- r.keys("*")
193
- end
194
-
195
- assert_equal ["key"], result.first
196
- end
197
-
198
- def test_pipeline_yields_a_connection
199
- r.pipelined do |p|
200
- p.set("foo", "bar")
201
- end
202
-
203
- assert_equal "bar", r.get("foo")
204
- end
205
-
206
- def test_pipeline_select
207
- r.select 1
208
- r.set("db", "1")
209
-
210
- r.pipelined do |p|
211
- p.select 2
212
- p.set("db", "2")
213
- end
214
-
215
- r.select 1
216
- assert_equal "1", r.get("db")
217
-
218
- r.select 2
219
- assert_equal "2", r.get("db")
220
- end
221
-
222
- def test_pipeline_select_client_db
223
- r.select 1
224
- r.pipelined do |p2|
225
- p2.select 2
226
- end
227
-
228
- assert_equal 2, r.client.db
229
- end
230
-
231
- def test_nested_pipeline_select_client_db
232
- r.select 1
233
- r.pipelined do |p2|
234
- p2.select 2
235
- p2.pipelined do |p3|
236
- p3.select 3
237
- end
238
- end
239
-
240
- assert_equal 3, r.client.db
241
- end
242
- end
@@ -1,282 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestPublishSubscribe < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- class TestError < StandardError
10
- end
11
-
12
- def test_subscribe_and_unsubscribe
13
- @subscribed = false
14
- @unsubscribed = false
15
-
16
- wire = Wire.new do
17
- r.subscribe("foo") do |on|
18
- on.subscribe do |channel, total|
19
- @subscribed = true
20
- @t1 = total
21
- end
22
-
23
- on.message do |channel, message|
24
- if message == "s1"
25
- r.unsubscribe
26
- @message = message
27
- end
28
- end
29
-
30
- on.unsubscribe do |channel, total|
31
- @unsubscribed = true
32
- @t2 = total
33
- end
34
- end
35
- end
36
-
37
- # Wait until the subscription is active before publishing
38
- Wire.pass while !@subscribed
39
-
40
- Redis.new(OPTIONS).publish("foo", "s1")
41
-
42
- wire.join
43
-
44
- assert @subscribed
45
- assert_equal 1, @t1
46
- assert @unsubscribed
47
- assert_equal 0, @t2
48
- assert_equal "s1", @message
49
- end
50
-
51
- def test_psubscribe_and_punsubscribe
52
- @subscribed = false
53
- @unsubscribed = false
54
-
55
- wire = Wire.new do
56
- r.psubscribe("f*") do |on|
57
- on.psubscribe do |pattern, total|
58
- @subscribed = true
59
- @t1 = total
60
- end
61
-
62
- on.pmessage do |pattern, channel, message|
63
- if message == "s1"
64
- r.punsubscribe
65
- @message = message
66
- end
67
- end
68
-
69
- on.punsubscribe do |pattern, total|
70
- @unsubscribed = true
71
- @t2 = total
72
- end
73
- end
74
- end
75
-
76
- # Wait until the subscription is active before publishing
77
- Wire.pass while !@subscribed
78
-
79
- Redis.new(OPTIONS).publish("foo", "s1")
80
-
81
- wire.join
82
-
83
- assert @subscribed
84
- assert_equal 1, @t1
85
- assert @unsubscribed
86
- assert_equal 0, @t2
87
- assert_equal "s1", @message
88
- end
89
-
90
- def test_pubsub_with_numpat_subcommand
91
- target_version("2.8.0") do
92
- @subscribed = false
93
- wire = Wire.new do
94
- r.psubscribe("f*") do |on|
95
- on.psubscribe { |channel, total| @subscribed = true }
96
- on.pmessage { |pattern, channel, message| r.punsubscribe }
97
- end
98
- end
99
- Wire.pass while !@subscribed
100
- redis = Redis.new(OPTIONS)
101
- numpat_result = redis.pubsub(:numpat)
102
-
103
- redis.publish("foo", "s1")
104
- wire.join
105
-
106
- assert_equal redis.pubsub(:numpat), 0
107
- assert_equal numpat_result, 1
108
- end
109
- end
110
-
111
-
112
- def test_pubsub_with_channels_and_numsub_subcommnads
113
- target_version("2.8.0") do
114
- @subscribed = false
115
- wire = Wire.new do
116
- r.subscribe("foo") do |on|
117
- on.subscribe { |channel, total| @subscribed = true }
118
- on.message { |channel, message| r.unsubscribe }
119
- end
120
- end
121
- Wire.pass while !@subscribed
122
- redis = Redis.new(OPTIONS)
123
- channels_result = redis.pubsub(:channels)
124
- numsub_result = redis.pubsub(:numsub, 'foo', 'boo')
125
-
126
- redis.publish("foo", "s1")
127
- wire.join
128
-
129
- assert_equal channels_result, ['foo']
130
- assert_equal numsub_result, ['foo', 1, 'boo', 0]
131
- end
132
- end
133
-
134
- def test_subscribe_connection_usable_after_raise
135
- @subscribed = false
136
-
137
- wire = Wire.new do
138
- begin
139
- r.subscribe("foo") do |on|
140
- on.subscribe do |channel, total|
141
- @subscribed = true
142
- end
143
-
144
- on.message do |channel, message|
145
- raise TestError
146
- end
147
- end
148
- rescue TestError
149
- end
150
- end
151
-
152
- # Wait until the subscription is active before publishing
153
- Wire.pass while !@subscribed
154
-
155
- Redis.new(OPTIONS).publish("foo", "s1")
156
-
157
- wire.join
158
-
159
- assert_equal "PONG", r.ping
160
- end
161
-
162
- def test_psubscribe_connection_usable_after_raise
163
- @subscribed = false
164
-
165
- wire = Wire.new do
166
- begin
167
- r.psubscribe("f*") do |on|
168
- on.psubscribe do |pattern, total|
169
- @subscribed = true
170
- end
171
-
172
- on.pmessage do |pattern, channel, message|
173
- raise TestError
174
- end
175
- end
176
- rescue TestError
177
- end
178
- end
179
-
180
- # Wait until the subscription is active before publishing
181
- Wire.pass while !@subscribed
182
-
183
- Redis.new(OPTIONS).publish("foo", "s1")
184
-
185
- wire.join
186
-
187
- assert_equal "PONG", r.ping
188
- end
189
-
190
- def test_subscribe_within_subscribe
191
- @channels = []
192
-
193
- wire = Wire.new do
194
- r.subscribe("foo") do |on|
195
- on.subscribe do |channel, total|
196
- @channels << channel
197
-
198
- r.subscribe("bar") if channel == "foo"
199
- r.unsubscribe if channel == "bar"
200
- end
201
- end
202
- end
203
-
204
- wire.join
205
-
206
- assert_equal ["foo", "bar"], @channels
207
- end
208
-
209
- def test_other_commands_within_a_subscribe
210
- assert_raise Redis::CommandError do
211
- r.subscribe("foo") do |on|
212
- on.subscribe do |channel, total|
213
- r.set("bar", "s2")
214
- end
215
- end
216
- end
217
- end
218
-
219
- def test_subscribe_without_a_block
220
- assert_raise LocalJumpError do
221
- r.subscribe("foo")
222
- end
223
- end
224
-
225
- def test_unsubscribe_without_a_subscribe
226
- assert_raise RuntimeError do
227
- r.unsubscribe
228
- end
229
-
230
- assert_raise RuntimeError do
231
- r.punsubscribe
232
- end
233
- end
234
-
235
- def test_subscribe_past_a_timeout
236
- # For some reason, a thread here doesn't reproduce the issue.
237
- sleep = %{sleep #{OPTIONS[:timeout] * 2}}
238
- 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'}
239
- cmd = [sleep, publish].join("; ")
240
-
241
- IO.popen(cmd, "r+") do |pipe|
242
- received = false
243
-
244
- r.subscribe "foo" do |on|
245
- on.message do |channel, message|
246
- received = true
247
- r.unsubscribe
248
- end
249
- end
250
-
251
- assert received
252
- end
253
- end
254
-
255
- def test_subscribe_with_timeout
256
- received = false
257
-
258
- assert_raise Redis::TimeoutError do
259
- r.subscribe_with_timeout(1, "foo") do |on|
260
- on.message do |channel, message|
261
- received = true
262
- end
263
- end
264
- end
265
-
266
- assert !received
267
- end
268
-
269
- def test_psubscribe_with_timeout
270
- received = false
271
-
272
- assert_raise Redis::TimeoutError do
273
- r.psubscribe_with_timeout(1, "f*") do |on|
274
- on.message do |channel, message|
275
- received = true
276
- end
277
- end
278
- end
279
-
280
- assert !received
281
- end
282
- end
@@ -1,118 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestRemoteServerControlCommands < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_info
10
- keys = [
11
- "redis_version",
12
- "uptime_in_seconds",
13
- "uptime_in_days",
14
- "connected_clients",
15
- "used_memory",
16
- "total_connections_received",
17
- "total_commands_processed",
18
- ]
19
-
20
- info = r.info
21
-
22
- keys.each do |k|
23
- msg = "expected #info to include #{k}"
24
- assert info.keys.include?(k), msg
25
- end
26
- end
27
-
28
- def test_info_commandstats
29
- target_version "2.5.7" do
30
- r.config(:resetstat)
31
- r.ping
32
-
33
- result = r.info(:commandstats)
34
- assert_equal "1", result["ping"]["calls"]
35
- end
36
- end
37
-
38
- def test_monitor_redis_lt_2_5_0
39
- return unless version < "2.5.0"
40
-
41
- log = []
42
-
43
- wire = Wire.new do
44
- Redis.new(OPTIONS).monitor do |line|
45
- log << line
46
- break if log.size == 3
47
- end
48
- end
49
-
50
- Wire.pass while log.empty? # Faster than sleep
51
-
52
- r.set "foo", "s1"
53
-
54
- wire.join
55
-
56
- assert log[-1][%q{(db 15) "set" "foo" "s1"}]
57
- end
58
-
59
- def test_monitor_redis_gte_2_5_0
60
- return unless version >= "2.5.0"
61
-
62
- log = []
63
-
64
- wire = Wire.new do
65
- Redis.new(OPTIONS).monitor do |line|
66
- log << line
67
- break if line =~ /set/
68
- end
69
- end
70
-
71
- Wire.pass while log.empty? # Faster than sleep
72
-
73
- r.set "foo", "s1"
74
-
75
- wire.join
76
-
77
- assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/
78
- end
79
-
80
- def test_monitor_returns_value_for_break
81
- result = r.monitor do |line|
82
- break line
83
- end
84
-
85
- assert_equal "OK", result
86
- end
87
-
88
- def test_echo
89
- assert_equal "foo bar baz\n", r.echo("foo bar baz\n")
90
- end
91
-
92
- def test_debug
93
- r.set "foo", "s1"
94
-
95
- assert r.debug(:object, "foo").kind_of?(String)
96
- end
97
-
98
- def test_object
99
- r.lpush "list", "value"
100
-
101
- assert_equal 1, r.object(:refcount, "list")
102
- encoding = r.object(:encoding, "list")
103
- assert "ziplist" == encoding || "quicklist" == encoding, "Wrong encoding for list"
104
- assert r.object(:idletime, "list").kind_of?(Integer)
105
- end
106
-
107
- def test_sync
108
- redis_mock(:sync => lambda { "+OK" }) do |redis|
109
- assert_equal "OK", redis.sync
110
- end
111
- end
112
-
113
- def test_slowlog
114
- r.slowlog(:reset)
115
- result = r.slowlog(:len)
116
- assert_equal 0, result
117
- end
118
- end