redis 4.0.0.rc1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +143 -3
  3. data/README.md +127 -18
  4. data/lib/redis/client.rb +150 -93
  5. data/lib/redis/cluster/command.rb +81 -0
  6. data/lib/redis/cluster/command_loader.rb +34 -0
  7. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  8. data/lib/redis/cluster/node.rb +108 -0
  9. data/lib/redis/cluster/node_key.rb +31 -0
  10. data/lib/redis/cluster/node_loader.rb +37 -0
  11. data/lib/redis/cluster/option.rb +93 -0
  12. data/lib/redis/cluster/slot.rb +86 -0
  13. data/lib/redis/cluster/slot_loader.rb +49 -0
  14. data/lib/redis/cluster.rb +291 -0
  15. data/lib/redis/connection/command_helper.rb +3 -2
  16. data/lib/redis/connection/hiredis.rb +4 -3
  17. data/lib/redis/connection/registry.rb +2 -1
  18. data/lib/redis/connection/ruby.rb +123 -105
  19. data/lib/redis/connection/synchrony.rb +18 -5
  20. data/lib/redis/connection.rb +2 -0
  21. data/lib/redis/distributed.rb +955 -0
  22. data/lib/redis/errors.rb +48 -0
  23. data/lib/redis/hash_ring.rb +89 -0
  24. data/lib/redis/pipeline.rb +55 -9
  25. data/lib/redis/subscribe.rb +11 -12
  26. data/lib/redis/version.rb +3 -1
  27. data/lib/redis.rb +1242 -381
  28. metadata +34 -141
  29. data/.gitignore +0 -16
  30. data/.travis/Gemfile +0 -11
  31. data/.travis.yml +0 -71
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -3
  34. data/benchmarking/logging.rb +0 -71
  35. data/benchmarking/pipeline.rb +0 -51
  36. data/benchmarking/speed.rb +0 -21
  37. data/benchmarking/suite.rb +0 -24
  38. data/benchmarking/worker.rb +0 -71
  39. data/examples/basic.rb +0 -15
  40. data/examples/consistency.rb +0 -114
  41. data/examples/incr-decr.rb +0 -17
  42. data/examples/list.rb +0 -26
  43. data/examples/pubsub.rb +0 -37
  44. data/examples/sentinel/sentinel.conf +0 -9
  45. data/examples/sentinel/start +0 -49
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sets.rb +0 -36
  48. data/examples/unicorn/config.ru +0 -3
  49. data/examples/unicorn/unicorn.rb +0 -20
  50. data/makefile +0 -42
  51. data/redis.gemspec +0 -40
  52. data/test/bitpos_test.rb +0 -63
  53. data/test/blocking_commands_test.rb +0 -183
  54. data/test/client_test.rb +0 -59
  55. data/test/command_map_test.rb +0 -28
  56. data/test/commands_on_hashes_test.rb +0 -174
  57. data/test/commands_on_hyper_log_log_test.rb +0 -70
  58. data/test/commands_on_lists_test.rb +0 -154
  59. data/test/commands_on_sets_test.rb +0 -208
  60. data/test/commands_on_sorted_sets_test.rb +0 -444
  61. data/test/commands_on_strings_test.rb +0 -338
  62. data/test/commands_on_value_types_test.rb +0 -246
  63. data/test/connection_handling_test.rb +0 -275
  64. data/test/db/.gitkeep +0 -0
  65. data/test/encoding_test.rb +0 -14
  66. data/test/error_replies_test.rb +0 -57
  67. data/test/fork_safety_test.rb +0 -60
  68. data/test/helper.rb +0 -179
  69. data/test/helper_test.rb +0 -22
  70. data/test/internals_test.rb +0 -435
  71. data/test/persistence_control_commands_test.rb +0 -24
  72. data/test/pipelining_commands_test.rb +0 -238
  73. data/test/publish_subscribe_test.rb +0 -280
  74. data/test/remote_server_control_commands_test.rb +0 -175
  75. data/test/scanning_test.rb +0 -407
  76. data/test/scripting_test.rb +0 -76
  77. data/test/sentinel_command_test.rb +0 -78
  78. data/test/sentinel_test.rb +0 -253
  79. data/test/sorting_test.rb +0 -57
  80. data/test/ssl_test.rb +0 -69
  81. data/test/support/connection/hiredis.rb +0 -1
  82. data/test/support/connection/ruby.rb +0 -1
  83. data/test/support/connection/synchrony.rb +0 -17
  84. data/test/support/redis_mock.rb +0 -130
  85. data/test/support/ssl/gen_certs.sh +0 -31
  86. data/test/support/ssl/trusted-ca.crt +0 -25
  87. data/test/support/ssl/trusted-ca.key +0 -27
  88. data/test/support/ssl/trusted-cert.crt +0 -81
  89. data/test/support/ssl/trusted-cert.key +0 -28
  90. data/test/support/ssl/untrusted-ca.crt +0 -26
  91. data/test/support/ssl/untrusted-ca.key +0 -27
  92. data/test/support/ssl/untrusted-cert.crt +0 -82
  93. data/test/support/ssl/untrusted-cert.key +0 -28
  94. data/test/support/wire/synchrony.rb +0 -24
  95. data/test/support/wire/thread.rb +0 -5
  96. data/test/synchrony_driver.rb +0 -85
  97. data/test/test.conf.erb +0 -9
  98. data/test/thread_safety_test.rb +0 -60
  99. data/test/transactions_test.rb +0 -262
  100. data/test/unknown_commands_test.rb +0 -12
  101. data/test/url_param_test.rb +0 -136
@@ -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?(Fixnum)
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