redis 3.3.5 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +132 -2
  3. data/README.md +144 -79
  4. data/lib/redis.rb +1174 -405
  5. data/lib/redis/client.rb +150 -90
  6. data/lib/redis/cluster.rb +295 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +107 -0
  11. data/lib/redis/cluster/node_key.rb +31 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +93 -0
  14. data/lib/redis/cluster/slot.rb +86 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +4 -2
  17. data/lib/redis/connection/command_helper.rb +5 -10
  18. data/lib/redis/connection/hiredis.rb +6 -5
  19. data/lib/redis/connection/registry.rb +2 -1
  20. data/lib/redis/connection/ruby.rb +126 -128
  21. data/lib/redis/connection/synchrony.rb +21 -8
  22. data/lib/redis/distributed.rb +147 -72
  23. data/lib/redis/errors.rb +48 -0
  24. data/lib/redis/hash_ring.rb +30 -73
  25. data/lib/redis/pipeline.rb +55 -15
  26. data/lib/redis/subscribe.rb +11 -12
  27. data/lib/redis/version.rb +3 -1
  28. metadata +49 -202
  29. data/.gitignore +0 -16
  30. data/.travis.yml +0 -89
  31. data/.travis/Gemfile +0 -11
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -4
  34. data/Rakefile +0 -87
  35. data/benchmarking/logging.rb +0 -71
  36. data/benchmarking/pipeline.rb +0 -51
  37. data/benchmarking/speed.rb +0 -21
  38. data/benchmarking/suite.rb +0 -24
  39. data/benchmarking/worker.rb +0 -71
  40. data/examples/basic.rb +0 -15
  41. data/examples/consistency.rb +0 -114
  42. data/examples/dist_redis.rb +0 -43
  43. data/examples/incr-decr.rb +0 -17
  44. data/examples/list.rb +0 -26
  45. data/examples/pubsub.rb +0 -37
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sets.rb +0 -36
  50. data/examples/unicorn/config.ru +0 -3
  51. data/examples/unicorn/unicorn.rb +0 -20
  52. data/redis.gemspec +0 -44
  53. data/test/bitpos_test.rb +0 -69
  54. data/test/blocking_commands_test.rb +0 -42
  55. data/test/client_test.rb +0 -59
  56. data/test/command_map_test.rb +0 -30
  57. data/test/commands_on_hashes_test.rb +0 -21
  58. data/test/commands_on_hyper_log_log_test.rb +0 -21
  59. data/test/commands_on_lists_test.rb +0 -20
  60. data/test/commands_on_sets_test.rb +0 -77
  61. data/test/commands_on_sorted_sets_test.rb +0 -137
  62. data/test/commands_on_strings_test.rb +0 -101
  63. data/test/commands_on_value_types_test.rb +0 -133
  64. data/test/connection_handling_test.rb +0 -277
  65. data/test/connection_test.rb +0 -57
  66. data/test/db/.gitkeep +0 -0
  67. data/test/distributed_blocking_commands_test.rb +0 -46
  68. data/test/distributed_commands_on_hashes_test.rb +0 -10
  69. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  70. data/test/distributed_commands_on_lists_test.rb +0 -22
  71. data/test/distributed_commands_on_sets_test.rb +0 -83
  72. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  73. data/test/distributed_commands_on_strings_test.rb +0 -59
  74. data/test/distributed_commands_on_value_types_test.rb +0 -95
  75. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  76. data/test/distributed_connection_handling_test.rb +0 -23
  77. data/test/distributed_internals_test.rb +0 -79
  78. data/test/distributed_key_tags_test.rb +0 -52
  79. data/test/distributed_persistence_control_commands_test.rb +0 -26
  80. data/test/distributed_publish_subscribe_test.rb +0 -92
  81. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  82. data/test/distributed_scripting_test.rb +0 -102
  83. data/test/distributed_sorting_test.rb +0 -20
  84. data/test/distributed_test.rb +0 -58
  85. data/test/distributed_transactions_test.rb +0 -32
  86. data/test/encoding_test.rb +0 -18
  87. data/test/error_replies_test.rb +0 -59
  88. data/test/fork_safety_test.rb +0 -65
  89. data/test/helper.rb +0 -232
  90. data/test/helper_test.rb +0 -24
  91. data/test/internals_test.rb +0 -417
  92. data/test/lint/blocking_commands.rb +0 -150
  93. data/test/lint/hashes.rb +0 -162
  94. data/test/lint/hyper_log_log.rb +0 -60
  95. data/test/lint/lists.rb +0 -143
  96. data/test/lint/sets.rb +0 -140
  97. data/test/lint/sorted_sets.rb +0 -316
  98. data/test/lint/strings.rb +0 -260
  99. data/test/lint/value_types.rb +0 -122
  100. data/test/persistence_control_commands_test.rb +0 -26
  101. data/test/pipelining_commands_test.rb +0 -242
  102. data/test/publish_subscribe_test.rb +0 -282
  103. data/test/remote_server_control_commands_test.rb +0 -118
  104. data/test/scanning_test.rb +0 -413
  105. data/test/scripting_test.rb +0 -78
  106. data/test/sentinel_command_test.rb +0 -80
  107. data/test/sentinel_test.rb +0 -255
  108. data/test/sorting_test.rb +0 -59
  109. data/test/ssl_test.rb +0 -73
  110. data/test/support/connection/hiredis.rb +0 -1
  111. data/test/support/connection/ruby.rb +0 -1
  112. data/test/support/connection/synchrony.rb +0 -17
  113. data/test/support/redis_mock.rb +0 -130
  114. data/test/support/ssl/gen_certs.sh +0 -31
  115. data/test/support/ssl/trusted-ca.crt +0 -25
  116. data/test/support/ssl/trusted-ca.key +0 -27
  117. data/test/support/ssl/trusted-cert.crt +0 -81
  118. data/test/support/ssl/trusted-cert.key +0 -28
  119. data/test/support/ssl/untrusted-ca.crt +0 -26
  120. data/test/support/ssl/untrusted-ca.key +0 -27
  121. data/test/support/ssl/untrusted-cert.crt +0 -82
  122. data/test/support/ssl/untrusted-cert.key +0 -28
  123. data/test/support/wire/synchrony.rb +0 -24
  124. data/test/support/wire/thread.rb +0 -5
  125. data/test/synchrony_driver.rb +0 -88
  126. data/test/test.conf.erb +0 -9
  127. data/test/thread_safety_test.rb +0 -62
  128. data/test/transactions_test.rb +0 -264
  129. data/test/unknown_commands_test.rb +0 -14
  130. data/test/url_param_test.rb +0 -138
@@ -1,122 +0,0 @@
1
- module Lint
2
-
3
- module ValueTypes
4
-
5
- def test_exists
6
- assert_equal false, r.exists("foo")
7
-
8
- r.set("foo", "s1")
9
-
10
- assert_equal true, r.exists("foo")
11
- end
12
-
13
- def test_type
14
- assert_equal "none", r.type("foo")
15
-
16
- r.set("foo", "s1")
17
-
18
- assert_equal "string", r.type("foo")
19
- end
20
-
21
- def test_keys
22
- r.set("f", "s1")
23
- r.set("fo", "s2")
24
- r.set("foo", "s3")
25
-
26
- assert_equal ["f","fo", "foo"], r.keys("f*").sort
27
- end
28
-
29
- def test_expire
30
- r.set("foo", "s1")
31
- assert r.expire("foo", 2)
32
- assert_in_range 0..2, r.ttl("foo")
33
- end
34
-
35
- def test_pexpire
36
- target_version "2.5.4" do
37
- r.set("foo", "s1")
38
- assert r.pexpire("foo", 2000)
39
- assert_in_range 0..2, r.ttl("foo")
40
- end
41
- end
42
-
43
- def test_expireat
44
- r.set("foo", "s1")
45
- assert r.expireat("foo", (Time.now + 2).to_i)
46
- assert_in_range 0..2, r.ttl("foo")
47
- end
48
-
49
- def test_pexpireat
50
- target_version "2.5.4" do
51
- r.set("foo", "s1")
52
- assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)
53
- assert_in_range 0..2, r.ttl("foo")
54
- end
55
- end
56
-
57
- def test_persist
58
- r.set("foo", "s1")
59
- r.expire("foo", 1)
60
- r.persist("foo")
61
-
62
- assert(-1 == r.ttl("foo"))
63
- end
64
-
65
- def test_ttl
66
- r.set("foo", "s1")
67
- r.expire("foo", 2)
68
- assert_in_range 0..2, r.ttl("foo")
69
- end
70
-
71
- def test_pttl
72
- target_version "2.5.4" do
73
- r.set("foo", "s1")
74
- r.expire("foo", 2)
75
- assert_in_range 1..2000, r.pttl("foo")
76
- end
77
- end
78
-
79
- def test_dump_and_restore
80
- target_version "2.5.7" do
81
- r.set("foo", "a")
82
- v = r.dump("foo")
83
- r.del("foo")
84
-
85
- assert r.restore("foo", 1000, v)
86
- assert_equal "a", r.get("foo")
87
- assert [0, 1].include? r.ttl("foo")
88
-
89
- r.rpush("bar", ["b", "c", "d"])
90
- w = r.dump("bar")
91
- r.del("bar")
92
-
93
- assert r.restore("bar", 1000, w)
94
- assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
95
- assert [0, 1].include? r.ttl("bar")
96
- end
97
- end
98
-
99
- def test_move
100
- r.select 14
101
- r.flushdb
102
-
103
- r.set "bar", "s3"
104
-
105
- r.select 15
106
-
107
- r.set "foo", "s1"
108
- r.set "bar", "s2"
109
-
110
- assert r.move("foo", 14)
111
- assert_equal nil, r.get("foo")
112
-
113
- assert !r.move("bar", 14)
114
- assert_equal "s2", r.get("bar")
115
-
116
- r.select 14
117
-
118
- assert_equal "s1", r.get("foo")
119
- assert_equal "s3", r.get("bar")
120
- end
121
- end
122
- end
@@ -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