redis 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +46 -1
  4. data/lib/redis/client.rb +29 -12
  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 +104 -0
  9. data/lib/redis/cluster/node_key.rb +35 -0
  10. data/lib/redis/cluster/node_loader.rb +37 -0
  11. data/lib/redis/cluster/option.rb +77 -0
  12. data/lib/redis/cluster/slot.rb +69 -0
  13. data/lib/redis/cluster/slot_loader.rb +49 -0
  14. data/lib/redis/cluster.rb +286 -0
  15. data/lib/redis/connection/ruby.rb +5 -2
  16. data/lib/redis/distributed.rb +13 -6
  17. data/lib/redis/errors.rb +46 -0
  18. data/lib/redis/pipeline.rb +9 -1
  19. data/lib/redis/version.rb +1 -1
  20. data/lib/redis.rb +692 -25
  21. metadata +27 -184
  22. data/.gitignore +0 -16
  23. data/.travis/Gemfile +0 -13
  24. data/.travis.yml +0 -73
  25. data/.yardopts +0 -3
  26. data/Gemfile +0 -3
  27. data/benchmarking/logging.rb +0 -71
  28. data/benchmarking/pipeline.rb +0 -51
  29. data/benchmarking/speed.rb +0 -21
  30. data/benchmarking/suite.rb +0 -24
  31. data/benchmarking/worker.rb +0 -71
  32. data/bors.toml +0 -14
  33. data/examples/basic.rb +0 -15
  34. data/examples/consistency.rb +0 -114
  35. data/examples/dist_redis.rb +0 -43
  36. data/examples/incr-decr.rb +0 -17
  37. data/examples/list.rb +0 -26
  38. data/examples/pubsub.rb +0 -37
  39. data/examples/sentinel/sentinel.conf +0 -9
  40. data/examples/sentinel/start +0 -49
  41. data/examples/sentinel.rb +0 -41
  42. data/examples/sets.rb +0 -36
  43. data/examples/unicorn/config.ru +0 -3
  44. data/examples/unicorn/unicorn.rb +0 -20
  45. data/makefile +0 -42
  46. data/redis.gemspec +0 -42
  47. data/test/bitpos_test.rb +0 -63
  48. data/test/blocking_commands_test.rb +0 -40
  49. data/test/client_test.rb +0 -59
  50. data/test/command_map_test.rb +0 -28
  51. data/test/commands_on_hashes_test.rb +0 -19
  52. data/test/commands_on_hyper_log_log_test.rb +0 -19
  53. data/test/commands_on_lists_test.rb +0 -18
  54. data/test/commands_on_sets_test.rb +0 -75
  55. data/test/commands_on_sorted_sets_test.rb +0 -150
  56. data/test/commands_on_strings_test.rb +0 -99
  57. data/test/commands_on_value_types_test.rb +0 -171
  58. data/test/connection_handling_test.rb +0 -275
  59. data/test/connection_test.rb +0 -57
  60. data/test/db/.gitkeep +0 -0
  61. data/test/distributed_blocking_commands_test.rb +0 -44
  62. data/test/distributed_commands_on_hashes_test.rb +0 -8
  63. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -31
  64. data/test/distributed_commands_on_lists_test.rb +0 -20
  65. data/test/distributed_commands_on_sets_test.rb +0 -106
  66. data/test/distributed_commands_on_sorted_sets_test.rb +0 -16
  67. data/test/distributed_commands_on_strings_test.rb +0 -69
  68. data/test/distributed_commands_on_value_types_test.rb +0 -93
  69. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  70. data/test/distributed_connection_handling_test.rb +0 -21
  71. data/test/distributed_internals_test.rb +0 -68
  72. data/test/distributed_key_tags_test.rb +0 -50
  73. data/test/distributed_persistence_control_commands_test.rb +0 -24
  74. data/test/distributed_publish_subscribe_test.rb +0 -90
  75. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  76. data/test/distributed_scripting_test.rb +0 -100
  77. data/test/distributed_sorting_test.rb +0 -18
  78. data/test/distributed_test.rb +0 -56
  79. data/test/distributed_transactions_test.rb +0 -30
  80. data/test/encoding_test.rb +0 -14
  81. data/test/error_replies_test.rb +0 -57
  82. data/test/fork_safety_test.rb +0 -60
  83. data/test/helper.rb +0 -201
  84. data/test/helper_test.rb +0 -22
  85. data/test/internals_test.rb +0 -389
  86. data/test/lint/blocking_commands.rb +0 -150
  87. data/test/lint/hashes.rb +0 -162
  88. data/test/lint/hyper_log_log.rb +0 -60
  89. data/test/lint/lists.rb +0 -143
  90. data/test/lint/sets.rb +0 -140
  91. data/test/lint/sorted_sets.rb +0 -316
  92. data/test/lint/strings.rb +0 -246
  93. data/test/lint/value_types.rb +0 -130
  94. data/test/persistence_control_commands_test.rb +0 -24
  95. data/test/pipelining_commands_test.rb +0 -238
  96. data/test/publish_subscribe_test.rb +0 -280
  97. data/test/remote_server_control_commands_test.rb +0 -175
  98. data/test/scanning_test.rb +0 -407
  99. data/test/scripting_test.rb +0 -76
  100. data/test/sentinel_command_test.rb +0 -78
  101. data/test/sentinel_test.rb +0 -253
  102. data/test/sorting_test.rb +0 -57
  103. data/test/ssl_test.rb +0 -69
  104. data/test/support/connection/hiredis.rb +0 -1
  105. data/test/support/connection/ruby.rb +0 -1
  106. data/test/support/connection/synchrony.rb +0 -17
  107. data/test/support/redis_mock.rb +0 -130
  108. data/test/support/ssl/gen_certs.sh +0 -31
  109. data/test/support/ssl/trusted-ca.crt +0 -25
  110. data/test/support/ssl/trusted-ca.key +0 -27
  111. data/test/support/ssl/trusted-cert.crt +0 -81
  112. data/test/support/ssl/trusted-cert.key +0 -28
  113. data/test/support/ssl/untrusted-ca.crt +0 -26
  114. data/test/support/ssl/untrusted-ca.key +0 -27
  115. data/test/support/ssl/untrusted-cert.crt +0 -82
  116. data/test/support/ssl/untrusted-cert.key +0 -28
  117. data/test/support/wire/synchrony.rb +0 -24
  118. data/test/support/wire/thread.rb +0 -5
  119. data/test/synchrony_driver.rb +0 -85
  120. data/test/test.conf.erb +0 -9
  121. data/test/thread_safety_test.rb +0 -60
  122. data/test/transactions_test.rb +0 -262
  123. data/test/unknown_commands_test.rb +0 -12
  124. data/test/url_param_test.rb +0 -136
@@ -1,262 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestTransactions < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_multi_discard
8
- r.multi
9
-
10
- assert_equal "QUEUED", r.set("foo", "1")
11
- assert_equal "QUEUED", r.get("foo")
12
-
13
- r.discard
14
-
15
- assert_equal nil, r.get("foo")
16
- end
17
-
18
- def test_multi_exec_with_a_block
19
- r.multi do |multi|
20
- multi.set "foo", "s1"
21
- end
22
-
23
- assert_equal "s1", r.get("foo")
24
- end
25
-
26
- def test_multi_exec_with_a_block_doesn_t_return_replies_for_multi_and_exec
27
- r1, r2, nothing_else = r.multi do |multi|
28
- multi.set "foo", "s1"
29
- multi.get "foo"
30
- end
31
-
32
- assert_equal "OK", r1
33
- assert_equal "s1", r2
34
- assert_equal nil, nothing_else
35
- end
36
-
37
- def test_assignment_inside_multi_exec_block
38
- r.multi do |m|
39
- @first = m.sadd("foo", 1)
40
- @second = m.sadd("foo", 1)
41
- end
42
-
43
- assert_equal true, @first.value
44
- assert_equal false, @second.value
45
- end
46
-
47
- # Although we could support accessing the values in these futures,
48
- # it doesn't make a lot of sense.
49
- def test_assignment_inside_multi_exec_block_with_delayed_command_errors
50
- assert_raise(Redis::CommandError) do
51
- r.multi do |m|
52
- @first = m.set("foo", "s1")
53
- @second = m.incr("foo") # not an integer
54
- @third = m.lpush("foo", "value") # wrong kind of value
55
- end
56
- end
57
-
58
- assert_equal "OK", @first.value
59
- assert_raise(Redis::CommandError) { @second.value }
60
- assert_raise(Redis::FutureNotReady) { @third.value }
61
- end
62
-
63
- def test_assignment_inside_multi_exec_block_with_immediate_command_errors
64
- assert_raise(Redis::CommandError) do
65
- r.multi do |m|
66
- m.doesnt_exist
67
- @first = m.sadd("foo", 1)
68
- @second = m.sadd("foo", 1)
69
- end
70
- end
71
-
72
- assert_raise(Redis::FutureNotReady) { @first.value }
73
- assert_raise(Redis::FutureNotReady) { @second.value }
74
- end
75
-
76
- def test_raise_immediate_errors_in_multi_exec
77
- assert_raise(RuntimeError) do
78
- r.multi do |multi|
79
- multi.set "bar", "s2"
80
- raise "Some error"
81
- multi.set "baz", "s3"
82
- end
83
- end
84
-
85
- assert_equal nil, r.get("bar")
86
- assert_equal nil, r.get("baz")
87
- end
88
-
89
- def test_transformed_replies_as_return_values_for_multi_exec_block
90
- info, _ = r.multi do |m|
91
- r.info
92
- end
93
-
94
- assert info.kind_of?(Hash)
95
- end
96
-
97
- def test_transformed_replies_inside_multi_exec_block
98
- r.multi do |m|
99
- @info = r.info
100
- end
101
-
102
- assert @info.value.kind_of?(Hash)
103
- end
104
-
105
- def test_raise_command_errors_in_multi_exec
106
- assert_raise(Redis::CommandError) do
107
- r.multi do |m|
108
- m.set("foo", "s1")
109
- m.incr("foo") # not an integer
110
- m.lpush("foo", "value") # wrong kind of value
111
- end
112
- end
113
-
114
- assert_equal "s1", r.get("foo")
115
- end
116
-
117
- def test_raise_command_errors_when_accessing_futures_after_multi_exec
118
- begin
119
- r.multi do |m|
120
- m.set("foo", "s1")
121
- @counter = m.incr("foo") # not an integer
122
- end
123
- rescue Exception
124
- # Not gonna deal with it
125
- end
126
-
127
- # We should test for Redis::Error here, but hiredis doesn't yet do
128
- # custom error classes.
129
- err = nil
130
- begin
131
- @counter.value
132
- rescue => err
133
- end
134
-
135
- assert err.kind_of?(RuntimeError)
136
- end
137
-
138
- def test_multi_with_a_block_yielding_the_client
139
- r.multi do |multi|
140
- multi.set "foo", "s1"
141
- end
142
-
143
- assert_equal "s1", r.get("foo")
144
- end
145
-
146
- def test_raise_command_error_when_exec_fails
147
- redis_mock(:exec => lambda { |*_| "-ERROR" }) do |redis|
148
- assert_raise(Redis::CommandError) do
149
- redis.multi do |m|
150
- m.set "foo", "s1"
151
- end
152
- end
153
- end
154
- end
155
-
156
- def test_watch
157
- res = r.watch "foo"
158
-
159
- assert_equal "OK", res
160
- end
161
-
162
- def test_watch_with_an_unmodified_key
163
- r.watch "foo"
164
- r.multi do |multi|
165
- multi.set "foo", "s1"
166
- end
167
-
168
- assert_equal "s1", r.get("foo")
169
- end
170
-
171
- def test_watch_with_an_unmodified_key_passed_as_array
172
- r.watch ["foo", "bar"]
173
- r.multi do |multi|
174
- multi.set "foo", "s1"
175
- end
176
-
177
- assert_equal "s1", r.get("foo")
178
- end
179
-
180
- def test_watch_with_a_modified_key
181
- r.watch "foo"
182
- r.set "foo", "s1"
183
- res = r.multi do |multi|
184
- multi.set "foo", "s2"
185
- end
186
-
187
- assert_equal nil, res
188
- assert_equal "s1", r.get("foo")
189
- end
190
-
191
- def test_watch_with_a_modified_key_passed_as_array
192
- r.watch ["foo", "bar"]
193
- r.set "foo", "s1"
194
- res = r.multi do |multi|
195
- multi.set "foo", "s2"
196
- end
197
-
198
- assert_equal nil, res
199
- assert_equal "s1", r.get("foo")
200
- end
201
-
202
- def test_watch_with_a_block_and_an_unmodified_key
203
- result = r.watch "foo" do |rd|
204
-
205
- assert_same r, rd
206
-
207
- rd.multi do |multi|
208
- multi.set "foo", "s1"
209
- end
210
- end
211
-
212
- assert_equal ["OK"], result
213
- assert_equal "s1", r.get("foo")
214
- end
215
-
216
- def test_watch_with_a_block_and_a_modified_key
217
- result = r.watch "foo" do |rd|
218
-
219
- assert_same r, rd
220
-
221
- rd.set "foo", "s1"
222
- rd.multi do |multi|
223
- multi.set "foo", "s2"
224
- end
225
- end
226
-
227
- assert_equal nil, result
228
- assert_equal "s1", r.get("foo")
229
- end
230
-
231
- def test_watch_with_a_block_that_raises_an_exception
232
- r.set("foo", "s1")
233
-
234
- begin
235
- r.watch "foo" do
236
- raise "test"
237
- end
238
- rescue RuntimeError
239
- end
240
-
241
- r.set("foo", "s2")
242
-
243
- # If the watch was still set from within the block above, this multi/exec
244
- # would fail. This proves that raising an exception above unwatches.
245
- r.multi do |multi|
246
- multi.set "foo", "s3"
247
- end
248
-
249
- assert_equal "s3", r.get("foo")
250
- end
251
-
252
- def test_unwatch_with_a_modified_key
253
- r.watch "foo"
254
- r.set "foo", "s1"
255
- r.unwatch
256
- r.multi do |multi|
257
- multi.set "foo", "s2"
258
- end
259
-
260
- assert_equal "s2", r.get("foo")
261
- end
262
- end
@@ -1,12 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestUnknownCommands < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_should_try_to_work
8
- assert_raise Redis::CommandError do
9
- r.not_yet_implemented_command
10
- end
11
- end
12
- end
@@ -1,136 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestUrlParam < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_url_defaults_to_______________
8
- redis = Redis.new
9
-
10
- assert_equal "127.0.0.1", redis._client.host
11
- assert_equal 6379, redis._client.port
12
- assert_equal 0, redis._client.db
13
- assert_equal nil, redis._client.password
14
- end
15
-
16
- def test_allows_to_pass_in_a_url
17
- redis = Redis.new :url => "redis://:secr3t@foo.com:999/2"
18
-
19
- assert_equal "foo.com", redis._client.host
20
- assert_equal 999, redis._client.port
21
- assert_equal 2, redis._client.db
22
- assert_equal "secr3t", redis._client.password
23
- end
24
-
25
- def test_allows_to_pass_in_a_url_with_string_key
26
- redis = Redis.new "url" => "redis://:secr3t@foo.com:999/2"
27
-
28
- assert_equal "foo.com", redis._client.host
29
- assert_equal 999, redis._client.port
30
- assert_equal 2, redis._client.db
31
- assert_equal "secr3t", redis._client.password
32
- end
33
-
34
- def test_unescape_password_from_url
35
- redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2"
36
-
37
- assert_equal "secr3t:", redis._client.password
38
- end
39
-
40
- def test_unescape_password_from_url_with_string_key
41
- redis = Redis.new "url" => "redis://:secr3t%3A@foo.com:999/2"
42
-
43
- assert_equal "secr3t:", redis._client.password
44
- end
45
-
46
- def test_does_not_unescape_password_when_explicitly_passed
47
- redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", :password => "secr3t%3A"
48
-
49
- assert_equal "secr3t%3A", redis._client.password
50
- end
51
-
52
- def test_does_not_unescape_password_when_explicitly_passed_with_string_key
53
- redis = Redis.new :url => "redis://:secr3t%3A@foo.com:999/2", "password" => "secr3t%3A"
54
-
55
- assert_equal "secr3t%3A", redis._client.password
56
- end
57
-
58
- def test_override_url_if_path_option_is_passed
59
- redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", :path => "/tmp/redis.sock"
60
-
61
- assert_equal "/tmp/redis.sock", redis._client.path
62
- assert_equal nil, redis._client.host
63
- assert_equal nil, redis._client.port
64
- end
65
-
66
- def test_override_url_if_path_option_is_passed_with_string_key
67
- redis = Redis.new :url => "redis://:secr3t@foo.com/foo:999/2", "path" => "/tmp/redis.sock"
68
-
69
- assert_equal "/tmp/redis.sock", redis._client.path
70
- assert_equal nil, redis._client.host
71
- assert_equal nil, redis._client.port
72
- end
73
-
74
- def test_overrides_url_if_another_connection_option_is_passed
75
- redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => 1000
76
-
77
- assert_equal "foo.com", redis._client.host
78
- assert_equal 1000, redis._client.port
79
- assert_equal 2, redis._client.db
80
- assert_equal "secr3t", redis._client.password
81
- end
82
-
83
- def test_overrides_url_if_another_connection_option_is_passed_with_string_key
84
- redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => 1000
85
-
86
- assert_equal "foo.com", redis._client.host
87
- assert_equal 1000, redis._client.port
88
- assert_equal 2, redis._client.db
89
- assert_equal "secr3t", redis._client.password
90
- end
91
-
92
- def test_does_not_overrides_url_if_a_nil_option_is_passed
93
- redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => nil
94
-
95
- assert_equal "foo.com", redis._client.host
96
- assert_equal 999, redis._client.port
97
- assert_equal 2, redis._client.db
98
- assert_equal "secr3t", redis._client.password
99
- end
100
-
101
- def test_does_not_overrides_url_if_a_nil_option_is_passed_with_string_key
102
- redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => nil
103
-
104
- assert_equal "foo.com", redis._client.host
105
- assert_equal 999, redis._client.port
106
- assert_equal 2, redis._client.db
107
- assert_equal "secr3t", redis._client.password
108
- end
109
-
110
- def test_does_not_modify_the_passed_options
111
- options = { :url => "redis://:secr3t@foo.com:999/2" }
112
-
113
- Redis.new(options)
114
-
115
- assert({ :url => "redis://:secr3t@foo.com:999/2" } == options)
116
- end
117
-
118
- def test_uses_redis_url_over_default_if_available
119
- ENV["REDIS_URL"] = "redis://:secr3t@foo.com:999/2"
120
-
121
- redis = Redis.new
122
-
123
- assert_equal "foo.com", redis._client.host
124
- assert_equal 999, redis._client.port
125
- assert_equal 2, redis._client.db
126
- assert_equal "secr3t", redis._client.password
127
-
128
- ENV.delete("REDIS_URL")
129
- end
130
-
131
- def test_defaults_to_localhost
132
- redis = Redis.new(:url => "redis:///")
133
-
134
- assert_equal "127.0.0.1", redis._client.host
135
- end
136
- end