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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -2
- data/README.md +45 -0
- data/lib/redis.rb +497 -20
- data/lib/redis/client.rb +14 -6
- data/lib/redis/cluster.rb +1 -0
- data/lib/redis/cluster/command_loader.rb +2 -0
- data/lib/redis/cluster/node_loader.rb +2 -0
- data/lib/redis/cluster/option.rb +1 -0
- data/lib/redis/cluster/slot_loader.rb +2 -0
- data/lib/redis/distributed.rb +3 -4
- data/lib/redis/version.rb +1 -1
- metadata +20 -243
- data/.gitignore +0 -19
- data/.travis.yml +0 -61
- data/.travis/Gemfile +0 -18
- data/.yardopts +0 -3
- data/Gemfile +0 -8
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/bin/build +0 -71
- data/bors.toml +0 -14
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel.rb +0 -41
- data/examples/sentinel/start +0 -49
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/makefile +0 -74
- data/redis.gemspec +0 -42
- data/test/bitpos_test.rb +0 -63
- data/test/blocking_commands_test.rb +0 -40
- data/test/client_test.rb +0 -76
- data/test/cluster_abnormal_state_test.rb +0 -38
- data/test/cluster_blocking_commands_test.rb +0 -15
- data/test/cluster_client_internals_test.rb +0 -77
- data/test/cluster_client_key_hash_tags_test.rb +0 -88
- data/test/cluster_client_options_test.rb +0 -147
- data/test/cluster_client_pipelining_test.rb +0 -59
- data/test/cluster_client_replicas_test.rb +0 -36
- data/test/cluster_client_slots_test.rb +0 -94
- data/test/cluster_client_transactions_test.rb +0 -71
- data/test/cluster_commands_on_cluster_test.rb +0 -165
- data/test/cluster_commands_on_connection_test.rb +0 -40
- data/test/cluster_commands_on_geo_test.rb +0 -74
- data/test/cluster_commands_on_hashes_test.rb +0 -11
- data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
- data/test/cluster_commands_on_keys_test.rb +0 -134
- data/test/cluster_commands_on_lists_test.rb +0 -15
- data/test/cluster_commands_on_pub_sub_test.rb +0 -101
- data/test/cluster_commands_on_scripting_test.rb +0 -56
- data/test/cluster_commands_on_server_test.rb +0 -221
- data/test/cluster_commands_on_sets_test.rb +0 -39
- data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
- data/test/cluster_commands_on_streams_test.rb +0 -196
- data/test/cluster_commands_on_strings_test.rb +0 -15
- data/test/cluster_commands_on_transactions_test.rb +0 -41
- data/test/cluster_commands_on_value_types_test.rb +0 -14
- data/test/command_map_test.rb +0 -28
- data/test/commands_on_geo_test.rb +0 -116
- data/test/commands_on_hashes_test.rb +0 -7
- data/test/commands_on_hyper_log_log_test.rb +0 -7
- data/test/commands_on_lists_test.rb +0 -7
- data/test/commands_on_sets_test.rb +0 -7
- data/test/commands_on_sorted_sets_test.rb +0 -7
- data/test/commands_on_strings_test.rb +0 -7
- data/test/commands_on_value_types_test.rb +0 -207
- data/test/connection_handling_test.rb +0 -275
- data/test/connection_test.rb +0 -57
- data/test/distributed_blocking_commands_test.rb +0 -52
- data/test/distributed_commands_on_hashes_test.rb +0 -21
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
- data/test/distributed_commands_on_lists_test.rb +0 -19
- data/test/distributed_commands_on_sets_test.rb +0 -105
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
- data/test/distributed_commands_on_strings_test.rb +0 -79
- data/test/distributed_commands_on_value_types_test.rb +0 -129
- data/test/distributed_commands_requiring_clustering_test.rb +0 -162
- data/test/distributed_connection_handling_test.rb +0 -21
- data/test/distributed_internals_test.rb +0 -68
- data/test/distributed_key_tags_test.rb +0 -50
- data/test/distributed_persistence_control_commands_test.rb +0 -24
- data/test/distributed_publish_subscribe_test.rb +0 -90
- data/test/distributed_remote_server_control_commands_test.rb +0 -64
- data/test/distributed_scripting_test.rb +0 -100
- data/test/distributed_sorting_test.rb +0 -18
- data/test/distributed_test.rb +0 -56
- data/test/distributed_transactions_test.rb +0 -30
- data/test/encoding_test.rb +0 -14
- data/test/error_replies_test.rb +0 -57
- data/test/fork_safety_test.rb +0 -60
- data/test/helper.rb +0 -344
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -395
- data/test/lint/blocking_commands.rb +0 -174
- data/test/lint/hashes.rb +0 -203
- data/test/lint/hyper_log_log.rb +0 -74
- data/test/lint/lists.rb +0 -159
- data/test/lint/sets.rb +0 -282
- data/test/lint/sorted_sets.rb +0 -497
- data/test/lint/strings.rb +0 -348
- data/test/lint/value_types.rb +0 -130
- data/test/persistence_control_commands_test.rb +0 -24
- data/test/pipelining_commands_test.rb +0 -246
- data/test/publish_subscribe_test.rb +0 -280
- data/test/remote_server_control_commands_test.rb +0 -175
- data/test/scanning_test.rb +0 -407
- data/test/scripting_test.rb +0 -76
- data/test/sentinel_command_test.rb +0 -78
- data/test/sentinel_test.rb +0 -253
- data/test/sorting_test.rb +0 -57
- data/test/ssl_test.rb +0 -69
- data/test/support/cluster/orchestrator.rb +0 -199
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -85
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -60
- data/test/transactions_test.rb +0 -272
- data/test/unknown_commands_test.rb +0 -12
- data/test/url_param_test.rb +0 -136
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestPersistenceControlCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_save
|
8
|
-
redis_mock(:save => lambda { "+SAVE" }) do |redis|
|
9
|
-
assert_equal "SAVE", redis.save
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_bgsave
|
14
|
-
redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
|
15
|
-
assert_equal "BGSAVE", redis.bgsave
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_lastsave
|
20
|
-
redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
|
21
|
-
assert_equal "LASTSAVE", redis.lastsave
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -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
|