redis 4.0.1 → 4.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +220 -0
  3. data/README.md +152 -28
  4. data/lib/redis/client.rb +171 -107
  5. data/lib/redis/cluster/command.rb +79 -0
  6. data/lib/redis/cluster/command_loader.rb +33 -0
  7. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  8. data/lib/redis/cluster/node.rb +120 -0
  9. data/lib/redis/cluster/node_key.rb +31 -0
  10. data/lib/redis/cluster/node_loader.rb +34 -0
  11. data/lib/redis/cluster/option.rb +100 -0
  12. data/lib/redis/cluster/slot.rb +86 -0
  13. data/lib/redis/cluster/slot_loader.rb +46 -0
  14. data/lib/redis/cluster.rb +315 -0
  15. data/lib/redis/commands/bitmaps.rb +63 -0
  16. data/lib/redis/commands/cluster.rb +45 -0
  17. data/lib/redis/commands/connection.rb +58 -0
  18. data/lib/redis/commands/geo.rb +84 -0
  19. data/lib/redis/commands/hashes.rb +251 -0
  20. data/lib/redis/commands/hyper_log_log.rb +37 -0
  21. data/lib/redis/commands/keys.rb +455 -0
  22. data/lib/redis/commands/lists.rb +290 -0
  23. data/lib/redis/commands/pubsub.rb +72 -0
  24. data/lib/redis/commands/scripting.rb +114 -0
  25. data/lib/redis/commands/server.rb +188 -0
  26. data/lib/redis/commands/sets.rb +223 -0
  27. data/lib/redis/commands/sorted_sets.rb +812 -0
  28. data/lib/redis/commands/streams.rb +382 -0
  29. data/lib/redis/commands/strings.rb +313 -0
  30. data/lib/redis/commands/transactions.rb +139 -0
  31. data/lib/redis/commands.rb +240 -0
  32. data/lib/redis/connection/command_helper.rb +5 -2
  33. data/lib/redis/connection/hiredis.rb +7 -5
  34. data/lib/redis/connection/registry.rb +2 -1
  35. data/lib/redis/connection/ruby.rb +139 -111
  36. data/lib/redis/connection/synchrony.rb +17 -10
  37. data/lib/redis/connection.rb +3 -1
  38. data/lib/redis/distributed.rb +244 -87
  39. data/lib/redis/errors.rb +57 -0
  40. data/lib/redis/hash_ring.rb +15 -14
  41. data/lib/redis/pipeline.rb +181 -10
  42. data/lib/redis/subscribe.rb +11 -12
  43. data/lib/redis/version.rb +3 -1
  44. data/lib/redis.rb +180 -2716
  45. metadata +45 -195
  46. data/.gitignore +0 -16
  47. data/.travis/Gemfile +0 -13
  48. data/.travis.yml +0 -73
  49. data/.yardopts +0 -3
  50. data/Gemfile +0 -3
  51. data/benchmarking/logging.rb +0 -71
  52. data/benchmarking/pipeline.rb +0 -51
  53. data/benchmarking/speed.rb +0 -21
  54. data/benchmarking/suite.rb +0 -24
  55. data/benchmarking/worker.rb +0 -71
  56. data/bors.toml +0 -14
  57. data/examples/basic.rb +0 -15
  58. data/examples/consistency.rb +0 -114
  59. data/examples/dist_redis.rb +0 -43
  60. data/examples/incr-decr.rb +0 -17
  61. data/examples/list.rb +0 -26
  62. data/examples/pubsub.rb +0 -37
  63. data/examples/sentinel/sentinel.conf +0 -9
  64. data/examples/sentinel/start +0 -49
  65. data/examples/sentinel.rb +0 -41
  66. data/examples/sets.rb +0 -36
  67. data/examples/unicorn/config.ru +0 -3
  68. data/examples/unicorn/unicorn.rb +0 -20
  69. data/makefile +0 -42
  70. data/redis.gemspec +0 -42
  71. data/test/bitpos_test.rb +0 -63
  72. data/test/blocking_commands_test.rb +0 -40
  73. data/test/client_test.rb +0 -59
  74. data/test/command_map_test.rb +0 -28
  75. data/test/commands_on_hashes_test.rb +0 -19
  76. data/test/commands_on_hyper_log_log_test.rb +0 -19
  77. data/test/commands_on_lists_test.rb +0 -18
  78. data/test/commands_on_sets_test.rb +0 -75
  79. data/test/commands_on_sorted_sets_test.rb +0 -150
  80. data/test/commands_on_strings_test.rb +0 -99
  81. data/test/commands_on_value_types_test.rb +0 -171
  82. data/test/connection_handling_test.rb +0 -275
  83. data/test/connection_test.rb +0 -57
  84. data/test/db/.gitkeep +0 -0
  85. data/test/distributed_blocking_commands_test.rb +0 -44
  86. data/test/distributed_commands_on_hashes_test.rb +0 -8
  87. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -31
  88. data/test/distributed_commands_on_lists_test.rb +0 -20
  89. data/test/distributed_commands_on_sets_test.rb +0 -106
  90. data/test/distributed_commands_on_sorted_sets_test.rb +0 -16
  91. data/test/distributed_commands_on_strings_test.rb +0 -69
  92. data/test/distributed_commands_on_value_types_test.rb +0 -93
  93. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  94. data/test/distributed_connection_handling_test.rb +0 -21
  95. data/test/distributed_internals_test.rb +0 -68
  96. data/test/distributed_key_tags_test.rb +0 -50
  97. data/test/distributed_persistence_control_commands_test.rb +0 -24
  98. data/test/distributed_publish_subscribe_test.rb +0 -90
  99. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  100. data/test/distributed_scripting_test.rb +0 -100
  101. data/test/distributed_sorting_test.rb +0 -18
  102. data/test/distributed_test.rb +0 -56
  103. data/test/distributed_transactions_test.rb +0 -30
  104. data/test/encoding_test.rb +0 -14
  105. data/test/error_replies_test.rb +0 -57
  106. data/test/fork_safety_test.rb +0 -60
  107. data/test/helper.rb +0 -201
  108. data/test/helper_test.rb +0 -22
  109. data/test/internals_test.rb +0 -389
  110. data/test/lint/blocking_commands.rb +0 -150
  111. data/test/lint/hashes.rb +0 -162
  112. data/test/lint/hyper_log_log.rb +0 -60
  113. data/test/lint/lists.rb +0 -143
  114. data/test/lint/sets.rb +0 -140
  115. data/test/lint/sorted_sets.rb +0 -316
  116. data/test/lint/strings.rb +0 -246
  117. data/test/lint/value_types.rb +0 -130
  118. data/test/persistence_control_commands_test.rb +0 -24
  119. data/test/pipelining_commands_test.rb +0 -238
  120. data/test/publish_subscribe_test.rb +0 -280
  121. data/test/remote_server_control_commands_test.rb +0 -175
  122. data/test/scanning_test.rb +0 -407
  123. data/test/scripting_test.rb +0 -76
  124. data/test/sentinel_command_test.rb +0 -78
  125. data/test/sentinel_test.rb +0 -253
  126. data/test/sorting_test.rb +0 -57
  127. data/test/ssl_test.rb +0 -69
  128. data/test/support/connection/hiredis.rb +0 -1
  129. data/test/support/connection/ruby.rb +0 -1
  130. data/test/support/connection/synchrony.rb +0 -17
  131. data/test/support/redis_mock.rb +0 -130
  132. data/test/support/ssl/gen_certs.sh +0 -31
  133. data/test/support/ssl/trusted-ca.crt +0 -25
  134. data/test/support/ssl/trusted-ca.key +0 -27
  135. data/test/support/ssl/trusted-cert.crt +0 -81
  136. data/test/support/ssl/trusted-cert.key +0 -28
  137. data/test/support/ssl/untrusted-ca.crt +0 -26
  138. data/test/support/ssl/untrusted-ca.key +0 -27
  139. data/test/support/ssl/untrusted-cert.crt +0 -82
  140. data/test/support/ssl/untrusted-cert.key +0 -28
  141. data/test/support/wire/synchrony.rb +0 -24
  142. data/test/support/wire/thread.rb +0 -5
  143. data/test/synchrony_driver.rb +0 -85
  144. data/test/test.conf.erb +0 -9
  145. data/test/thread_safety_test.rb +0 -60
  146. data/test/transactions_test.rb +0 -262
  147. data/test/unknown_commands_test.rb +0 -12
  148. 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