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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -2
  3. data/README.md +45 -0
  4. data/lib/redis.rb +497 -20
  5. data/lib/redis/client.rb +14 -6
  6. data/lib/redis/cluster.rb +1 -0
  7. data/lib/redis/cluster/command_loader.rb +2 -0
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +1 -0
  10. data/lib/redis/cluster/slot_loader.rb +2 -0
  11. data/lib/redis/distributed.rb +3 -4
  12. data/lib/redis/version.rb +1 -1
  13. metadata +20 -243
  14. data/.gitignore +0 -19
  15. data/.travis.yml +0 -61
  16. data/.travis/Gemfile +0 -18
  17. data/.yardopts +0 -3
  18. data/Gemfile +0 -8
  19. data/benchmarking/logging.rb +0 -71
  20. data/benchmarking/pipeline.rb +0 -51
  21. data/benchmarking/speed.rb +0 -21
  22. data/benchmarking/suite.rb +0 -24
  23. data/benchmarking/worker.rb +0 -71
  24. data/bin/build +0 -71
  25. data/bors.toml +0 -14
  26. data/examples/basic.rb +0 -15
  27. data/examples/consistency.rb +0 -114
  28. data/examples/dist_redis.rb +0 -43
  29. data/examples/incr-decr.rb +0 -17
  30. data/examples/list.rb +0 -26
  31. data/examples/pubsub.rb +0 -37
  32. data/examples/sentinel.rb +0 -41
  33. data/examples/sentinel/start +0 -49
  34. data/examples/sets.rb +0 -36
  35. data/examples/unicorn/config.ru +0 -3
  36. data/examples/unicorn/unicorn.rb +0 -20
  37. data/makefile +0 -74
  38. data/redis.gemspec +0 -42
  39. data/test/bitpos_test.rb +0 -63
  40. data/test/blocking_commands_test.rb +0 -40
  41. data/test/client_test.rb +0 -76
  42. data/test/cluster_abnormal_state_test.rb +0 -38
  43. data/test/cluster_blocking_commands_test.rb +0 -15
  44. data/test/cluster_client_internals_test.rb +0 -77
  45. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  46. data/test/cluster_client_options_test.rb +0 -147
  47. data/test/cluster_client_pipelining_test.rb +0 -59
  48. data/test/cluster_client_replicas_test.rb +0 -36
  49. data/test/cluster_client_slots_test.rb +0 -94
  50. data/test/cluster_client_transactions_test.rb +0 -71
  51. data/test/cluster_commands_on_cluster_test.rb +0 -165
  52. data/test/cluster_commands_on_connection_test.rb +0 -40
  53. data/test/cluster_commands_on_geo_test.rb +0 -74
  54. data/test/cluster_commands_on_hashes_test.rb +0 -11
  55. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  56. data/test/cluster_commands_on_keys_test.rb +0 -134
  57. data/test/cluster_commands_on_lists_test.rb +0 -15
  58. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  59. data/test/cluster_commands_on_scripting_test.rb +0 -56
  60. data/test/cluster_commands_on_server_test.rb +0 -221
  61. data/test/cluster_commands_on_sets_test.rb +0 -39
  62. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  63. data/test/cluster_commands_on_streams_test.rb +0 -196
  64. data/test/cluster_commands_on_strings_test.rb +0 -15
  65. data/test/cluster_commands_on_transactions_test.rb +0 -41
  66. data/test/cluster_commands_on_value_types_test.rb +0 -14
  67. data/test/command_map_test.rb +0 -28
  68. data/test/commands_on_geo_test.rb +0 -116
  69. data/test/commands_on_hashes_test.rb +0 -7
  70. data/test/commands_on_hyper_log_log_test.rb +0 -7
  71. data/test/commands_on_lists_test.rb +0 -7
  72. data/test/commands_on_sets_test.rb +0 -7
  73. data/test/commands_on_sorted_sets_test.rb +0 -7
  74. data/test/commands_on_strings_test.rb +0 -7
  75. data/test/commands_on_value_types_test.rb +0 -207
  76. data/test/connection_handling_test.rb +0 -275
  77. data/test/connection_test.rb +0 -57
  78. data/test/distributed_blocking_commands_test.rb +0 -52
  79. data/test/distributed_commands_on_hashes_test.rb +0 -21
  80. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  81. data/test/distributed_commands_on_lists_test.rb +0 -19
  82. data/test/distributed_commands_on_sets_test.rb +0 -105
  83. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  84. data/test/distributed_commands_on_strings_test.rb +0 -79
  85. data/test/distributed_commands_on_value_types_test.rb +0 -129
  86. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  87. data/test/distributed_connection_handling_test.rb +0 -21
  88. data/test/distributed_internals_test.rb +0 -68
  89. data/test/distributed_key_tags_test.rb +0 -50
  90. data/test/distributed_persistence_control_commands_test.rb +0 -24
  91. data/test/distributed_publish_subscribe_test.rb +0 -90
  92. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  93. data/test/distributed_scripting_test.rb +0 -100
  94. data/test/distributed_sorting_test.rb +0 -18
  95. data/test/distributed_test.rb +0 -56
  96. data/test/distributed_transactions_test.rb +0 -30
  97. data/test/encoding_test.rb +0 -14
  98. data/test/error_replies_test.rb +0 -57
  99. data/test/fork_safety_test.rb +0 -60
  100. data/test/helper.rb +0 -344
  101. data/test/helper_test.rb +0 -22
  102. data/test/internals_test.rb +0 -395
  103. data/test/lint/blocking_commands.rb +0 -174
  104. data/test/lint/hashes.rb +0 -203
  105. data/test/lint/hyper_log_log.rb +0 -74
  106. data/test/lint/lists.rb +0 -159
  107. data/test/lint/sets.rb +0 -282
  108. data/test/lint/sorted_sets.rb +0 -497
  109. data/test/lint/strings.rb +0 -348
  110. data/test/lint/value_types.rb +0 -130
  111. data/test/persistence_control_commands_test.rb +0 -24
  112. data/test/pipelining_commands_test.rb +0 -246
  113. data/test/publish_subscribe_test.rb +0 -280
  114. data/test/remote_server_control_commands_test.rb +0 -175
  115. data/test/scanning_test.rb +0 -407
  116. data/test/scripting_test.rb +0 -76
  117. data/test/sentinel_command_test.rb +0 -78
  118. data/test/sentinel_test.rb +0 -253
  119. data/test/sorting_test.rb +0 -57
  120. data/test/ssl_test.rb +0 -69
  121. data/test/support/cluster/orchestrator.rb +0 -199
  122. data/test/support/connection/hiredis.rb +0 -1
  123. data/test/support/connection/ruby.rb +0 -1
  124. data/test/support/connection/synchrony.rb +0 -17
  125. data/test/support/redis_mock.rb +0 -130
  126. data/test/support/ssl/gen_certs.sh +0 -31
  127. data/test/support/ssl/trusted-ca.crt +0 -25
  128. data/test/support/ssl/trusted-ca.key +0 -27
  129. data/test/support/ssl/trusted-cert.crt +0 -81
  130. data/test/support/ssl/trusted-cert.key +0 -28
  131. data/test/support/ssl/untrusted-ca.crt +0 -26
  132. data/test/support/ssl/untrusted-ca.key +0 -27
  133. data/test/support/ssl/untrusted-cert.crt +0 -82
  134. data/test/support/ssl/untrusted-cert.key +0 -28
  135. data/test/support/wire/synchrony.rb +0 -24
  136. data/test/support/wire/thread.rb +0 -5
  137. data/test/synchrony_driver.rb +0 -85
  138. data/test/test.conf.erb +0 -9
  139. data/test/thread_safety_test.rb +0 -60
  140. data/test/transactions_test.rb +0 -272
  141. data/test/unknown_commands_test.rb +0 -12
  142. data/test/url_param_test.rb +0 -136
@@ -1,9 +0,0 @@
1
- dir <%= REDIS_DIR %>
2
- pidfile <%= REDIS_PID %>
3
- port 6381
4
- unixsocket <%= REDIS_SOCKET %>
5
- timeout 300
6
- loglevel debug
7
- logfile <%= REDIS_LOG %>
8
- databases 16
9
- daemonize yes
@@ -1,60 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestThreadSafety < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- driver(:ruby, :hiredis) do
8
- def test_thread_safety
9
- redis = Redis.new(OPTIONS)
10
- redis.set "foo", 1
11
- redis.set "bar", 2
12
-
13
- sample = 100
14
-
15
- t1 = Thread.new do
16
- $foos = Array.new(sample) { redis.get "foo" }
17
- end
18
-
19
- t2 = Thread.new do
20
- $bars = Array.new(sample) { redis.get "bar" }
21
- end
22
-
23
- t1.join
24
- t2.join
25
-
26
- assert_equal ["1"], $foos.uniq
27
- assert_equal ["2"], $bars.uniq
28
- end
29
-
30
- def test_thread_safety_queue_commit
31
- redis = Redis.new(OPTIONS)
32
- redis.set "foo", 1
33
- redis.set "bar", 2
34
-
35
- sample = 100
36
-
37
- t1 = Thread.new do
38
- sample.times do
39
- r.queue("get", "foo")
40
- end
41
-
42
- $foos = r.commit
43
- end
44
-
45
- t2 = Thread.new do
46
- sample.times do
47
- r.queue("get", "bar")
48
- end
49
-
50
- $bars = r.commit
51
- end
52
-
53
- t1.join
54
- t2.join
55
-
56
- assert_equal ["1"], $foos.uniq
57
- assert_equal ["2"], $bars.uniq
58
- end
59
- end
60
- end
@@ -1,272 +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_empty_multi_exec
118
- result = nil
119
-
120
- redis_mock(:exec => lambda { |*_| "-ERROR" }) do |redis|
121
- result = redis.multi {}
122
- end
123
-
124
- assert_equal [], result
125
- end
126
-
127
- def test_raise_command_errors_when_accessing_futures_after_multi_exec
128
- begin
129
- r.multi do |m|
130
- m.set("foo", "s1")
131
- @counter = m.incr("foo") # not an integer
132
- end
133
- rescue Exception
134
- # Not gonna deal with it
135
- end
136
-
137
- # We should test for Redis::Error here, but hiredis doesn't yet do
138
- # custom error classes.
139
- err = nil
140
- begin
141
- @counter.value
142
- rescue => err
143
- end
144
-
145
- assert err.kind_of?(RuntimeError)
146
- end
147
-
148
- def test_multi_with_a_block_yielding_the_client
149
- r.multi do |multi|
150
- multi.set "foo", "s1"
151
- end
152
-
153
- assert_equal "s1", r.get("foo")
154
- end
155
-
156
- def test_raise_command_error_when_exec_fails
157
- redis_mock(:exec => lambda { |*_| "-ERROR" }) do |redis|
158
- assert_raise(Redis::CommandError) do
159
- redis.multi do |m|
160
- m.set "foo", "s1"
161
- end
162
- end
163
- end
164
- end
165
-
166
- def test_watch
167
- res = r.watch "foo"
168
-
169
- assert_equal "OK", res
170
- end
171
-
172
- def test_watch_with_an_unmodified_key
173
- r.watch "foo"
174
- r.multi do |multi|
175
- multi.set "foo", "s1"
176
- end
177
-
178
- assert_equal "s1", r.get("foo")
179
- end
180
-
181
- def test_watch_with_an_unmodified_key_passed_as_array
182
- r.watch ["foo", "bar"]
183
- r.multi do |multi|
184
- multi.set "foo", "s1"
185
- end
186
-
187
- assert_equal "s1", r.get("foo")
188
- end
189
-
190
- def test_watch_with_a_modified_key
191
- r.watch "foo"
192
- r.set "foo", "s1"
193
- res = r.multi do |multi|
194
- multi.set "foo", "s2"
195
- end
196
-
197
- assert_equal nil, res
198
- assert_equal "s1", r.get("foo")
199
- end
200
-
201
- def test_watch_with_a_modified_key_passed_as_array
202
- r.watch ["foo", "bar"]
203
- r.set "foo", "s1"
204
- res = r.multi do |multi|
205
- multi.set "foo", "s2"
206
- end
207
-
208
- assert_equal nil, res
209
- assert_equal "s1", r.get("foo")
210
- end
211
-
212
- def test_watch_with_a_block_and_an_unmodified_key
213
- result = r.watch "foo" do |rd|
214
-
215
- assert_same r, rd
216
-
217
- rd.multi do |multi|
218
- multi.set "foo", "s1"
219
- end
220
- end
221
-
222
- assert_equal ["OK"], result
223
- assert_equal "s1", r.get("foo")
224
- end
225
-
226
- def test_watch_with_a_block_and_a_modified_key
227
- result = r.watch "foo" do |rd|
228
-
229
- assert_same r, rd
230
-
231
- rd.set "foo", "s1"
232
- rd.multi do |multi|
233
- multi.set "foo", "s2"
234
- end
235
- end
236
-
237
- assert_equal nil, result
238
- assert_equal "s1", r.get("foo")
239
- end
240
-
241
- def test_watch_with_a_block_that_raises_an_exception
242
- r.set("foo", "s1")
243
-
244
- begin
245
- r.watch "foo" do
246
- raise "test"
247
- end
248
- rescue RuntimeError
249
- end
250
-
251
- r.set("foo", "s2")
252
-
253
- # If the watch was still set from within the block above, this multi/exec
254
- # would fail. This proves that raising an exception above unwatches.
255
- r.multi do |multi|
256
- multi.set "foo", "s3"
257
- end
258
-
259
- assert_equal "s3", r.get("foo")
260
- end
261
-
262
- def test_unwatch_with_a_modified_key
263
- r.watch "foo"
264
- r.set "foo", "s1"
265
- r.unwatch
266
- r.multi do |multi|
267
- multi.set "foo", "s2"
268
- end
269
-
270
- assert_equal "s2", r.get("foo")
271
- end
272
- 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