redis 4.1.0.beta1 → 4.1.0

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 (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,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/hashes'
3
-
4
- class TestCommandsOnHashes < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Hashes
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/hyper_log_log'
3
-
4
- class TestCommandsOnHyperLogLog < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::HyperLogLog
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/lists'
3
-
4
- class TestCommandsOnLists < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Lists
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/sets'
3
-
4
- class TestCommandsOnSets < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Sets
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/sorted_sets'
3
-
4
- class TestCommandsOnSortedSets < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::SortedSets
7
- end
@@ -1,7 +0,0 @@
1
- require_relative 'helper'
2
- require_relative 'lint/strings'
3
-
4
- class TestCommandsOnStrings < Test::Unit::TestCase
5
- include Helper::Client
6
- include Lint::Strings
7
- end
@@ -1,207 +0,0 @@
1
- require_relative "helper"
2
- require_relative "lint/value_types"
3
-
4
- class TestCommandsOnValueTypes < Test::Unit::TestCase
5
-
6
- include Helper::Client
7
- include Lint::ValueTypes
8
-
9
- def test_del
10
- r.set "foo", "s1"
11
- r.set "bar", "s2"
12
- r.set "baz", "s3"
13
-
14
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
15
-
16
- assert_equal 1, r.del("foo")
17
-
18
- assert_equal ["bar", "baz"], r.keys("*").sort
19
-
20
- assert_equal 2, r.del("bar", "baz")
21
-
22
- assert_equal [], r.keys("*").sort
23
- end
24
-
25
- def test_del_with_array_argument
26
- r.set "foo", "s1"
27
- r.set "bar", "s2"
28
- r.set "baz", "s3"
29
-
30
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
31
-
32
- assert_equal 1, r.del(["foo"])
33
-
34
- assert_equal ["bar", "baz"], r.keys("*").sort
35
-
36
- assert_equal 2, r.del(["bar", "baz"])
37
-
38
- assert_equal [], r.keys("*").sort
39
- end
40
-
41
- def test_unlink
42
- target_version "4.0.0" do
43
- r.set "foo", "s1"
44
- r.set "bar", "s2"
45
- r.set "baz", "s3"
46
-
47
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
48
-
49
- assert_equal 1, r.unlink("foo")
50
-
51
- assert_equal ["bar", "baz"], r.keys("*").sort
52
-
53
- assert_equal 2, r.unlink("bar", "baz")
54
-
55
- assert_equal [], r.keys("*").sort
56
- end
57
- end
58
-
59
- def test_unlink_with_array_argument
60
- target_version "4.0.0" do
61
- r.set "foo", "s1"
62
- r.set "bar", "s2"
63
- r.set "baz", "s3"
64
-
65
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
66
-
67
- assert_equal 1, r.unlink(["foo"])
68
-
69
- assert_equal ["bar", "baz"], r.keys("*").sort
70
-
71
- assert_equal 2, r.unlink(["bar", "baz"])
72
-
73
- assert_equal [], r.keys("*").sort
74
- end
75
- end
76
-
77
- def test_randomkey
78
- assert r.randomkey.to_s.empty?
79
-
80
- r.set("foo", "s1")
81
-
82
- assert_equal "foo", r.randomkey
83
-
84
- r.set("bar", "s2")
85
-
86
- 4.times do
87
- assert ["foo", "bar"].include?(r.randomkey)
88
- end
89
- end
90
-
91
- def test_rename
92
- r.set("foo", "s1")
93
- r.rename "foo", "bar"
94
-
95
- assert_equal "s1", r.get("bar")
96
- assert_equal nil, r.get("foo")
97
- end
98
-
99
- def test_renamenx
100
- r.set("foo", "s1")
101
- r.set("bar", "s2")
102
-
103
- assert_equal false, r.renamenx("foo", "bar")
104
-
105
- assert_equal "s1", r.get("foo")
106
- assert_equal "s2", r.get("bar")
107
- end
108
-
109
- def test_dbsize
110
- assert_equal 0, r.dbsize
111
-
112
- r.set("foo", "s1")
113
-
114
- assert_equal 1, r.dbsize
115
- end
116
-
117
- def test_flushdb
118
- # Test defaults
119
- r.set("foo", "s1")
120
- r.set("bar", "s2")
121
-
122
- assert_equal 2, r.dbsize
123
-
124
- r.flushdb
125
-
126
- assert_equal 0, r.dbsize
127
-
128
- # Test sync
129
- r.set("foo", "s1")
130
- r.set("bar", "s2")
131
-
132
- assert_equal 2, r.dbsize
133
-
134
- r.flushdb(:async => false)
135
-
136
- assert_equal 0, r.dbsize
137
-
138
- # Test async
139
- target_version "3.9.101" do
140
- r.set("foo", "s1")
141
- r.set("bar", "s2")
142
-
143
- assert_equal 2, r.dbsize
144
-
145
- r.flushdb(:async => true)
146
-
147
- assert_equal 0, r.dbsize
148
-
149
- redis_mock(:flushdb => lambda { |args| "+FLUSHDB #{args.upcase}" }) do |redis|
150
- assert_equal "FLUSHDB ASYNC", redis.flushdb(:async => true)
151
- end
152
- end
153
- end
154
-
155
- def test_flushall
156
- # Test defaults
157
- redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
158
- assert_equal "FLUSHALL", redis.flushall
159
- end
160
-
161
- # Test sync
162
- redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
163
- assert_equal "FLUSHALL", redis.flushall(:async => false)
164
- end
165
-
166
- # Test async
167
- target_version "3.9.101" do
168
- redis_mock(:flushall => lambda { |args| "+FLUSHALL #{args.upcase}" }) do |redis|
169
- assert_equal "FLUSHALL ASYNC", redis.flushall(:async => true)
170
- end
171
- end
172
- end
173
-
174
- def test_migrate
175
- redis_mock(:migrate => lambda { |*args| args }) do |redis|
176
- options = { :host => "127.0.0.1", :port => 1234 }
177
-
178
- ex = assert_raise(RuntimeError) do
179
- redis.migrate("foo", options.reject { |key, _| key == :host })
180
- end
181
- assert ex.message =~ /host not specified/
182
-
183
- ex = assert_raise(RuntimeError) do
184
- redis.migrate("foo", options.reject { |key, _| key == :port })
185
- end
186
- assert ex.message =~ /port not specified/
187
-
188
- default_db = redis._client.db.to_i
189
- default_timeout = redis._client.timeout.to_i
190
-
191
- # Test defaults
192
- actual = redis.migrate("foo", options)
193
- expected = ["127.0.0.1", "1234", "foo", default_db.to_s, default_timeout.to_s]
194
- assert_equal expected, actual
195
-
196
- # Test db override
197
- actual = redis.migrate("foo", options.merge(:db => default_db + 1))
198
- expected = ["127.0.0.1", "1234", "foo", (default_db + 1).to_s, default_timeout.to_s]
199
- assert_equal expected, actual
200
-
201
- # Test timeout override
202
- actual = redis.migrate("foo", options.merge(:timeout => default_timeout + 1))
203
- expected = ["127.0.0.1", "1234", "foo", default_db.to_s, (default_timeout + 1).to_s]
204
- assert_equal expected, actual
205
- end
206
- end
207
- end
@@ -1,275 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestConnectionHandling < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_auth
8
- commands = {
9
- :auth => lambda { |password| $auth = password; "+OK" },
10
- :get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
11
- }
12
-
13
- redis_mock(commands, :password => "secret") do |redis|
14
- assert_equal "bar", redis.get("foo")
15
- end
16
- end
17
-
18
- def test_id
19
- commands = {
20
- :client => lambda { |cmd, name| $name = [cmd, name]; "+OK" },
21
- :ping => lambda { "+PONG" },
22
- }
23
-
24
- redis_mock(commands, :id => "client-name") do |redis|
25
- assert_equal "PONG", redis.ping
26
- end
27
-
28
- assert_equal ["setname","client-name"], $name
29
- end
30
-
31
- def test_ping
32
- assert_equal "PONG", r.ping
33
- end
34
-
35
- def test_select
36
- r.set "foo", "bar"
37
-
38
- r.select 14
39
- assert_equal nil, r.get("foo")
40
-
41
- r._client.disconnect
42
-
43
- assert_equal nil, r.get("foo")
44
- end
45
-
46
- def test_quit
47
- r.quit
48
-
49
- assert !r._client.connected?
50
- end
51
-
52
- def test_close
53
- quit = 0
54
-
55
- commands = {
56
- :quit => lambda do
57
- quit += 1
58
- "+OK"
59
- end
60
- }
61
-
62
- redis_mock(commands) do |redis|
63
- assert_equal 0, quit
64
-
65
- redis.quit
66
-
67
- assert_equal 1, quit
68
-
69
- redis.ping
70
-
71
- redis.close
72
-
73
- assert_equal 1, quit
74
-
75
- assert !redis.connected?
76
- end
77
- end
78
-
79
- def test_disconnect
80
- quit = 0
81
-
82
- commands = {
83
- :quit => lambda do
84
- quit += 1
85
- "+OK"
86
- end
87
- }
88
-
89
- redis_mock(commands) do |redis|
90
- assert_equal 0, quit
91
-
92
- redis.quit
93
-
94
- assert_equal 1, quit
95
-
96
- redis.ping
97
-
98
- redis.disconnect!
99
-
100
- assert_equal 1, quit
101
-
102
- assert !redis.connected?
103
- end
104
- end
105
-
106
- def test_shutdown
107
- commands = {
108
- :shutdown => lambda { :exit }
109
- }
110
-
111
- redis_mock(commands) do |redis|
112
- # SHUTDOWN does not reply: test that it does not raise here.
113
- assert_equal nil, redis.shutdown
114
- end
115
- end
116
-
117
- def test_shutdown_with_error
118
- connections = 0
119
- commands = {
120
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
121
- :connections => lambda { ":#{connections}\r\n" },
122
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
123
- }
124
-
125
- redis_mock(commands) do |redis|
126
- connections = redis.connections
127
-
128
- # SHUTDOWN replies with an error: test that it gets raised
129
- assert_raise Redis::CommandError do
130
- redis.shutdown
131
- end
132
-
133
- # The connection should remain in tact
134
- assert_equal connections, redis.connections
135
- end
136
- end
137
-
138
- def test_shutdown_from_pipeline
139
- commands = {
140
- :shutdown => lambda { :exit }
141
- }
142
-
143
- redis_mock(commands) do |redis|
144
- result = redis.pipelined do
145
- redis.shutdown
146
- end
147
-
148
- assert_equal nil, result
149
- assert !redis._client.connected?
150
- end
151
- end
152
-
153
- def test_shutdown_with_error_from_pipeline
154
- connections = 0
155
- commands = {
156
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
157
- :connections => lambda { ":#{connections}\r\n" },
158
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
159
- }
160
-
161
- redis_mock(commands) do |redis|
162
- connections = redis.connections
163
-
164
- # SHUTDOWN replies with an error: test that it gets raised
165
- assert_raise Redis::CommandError do
166
- redis.pipelined do
167
- redis.shutdown
168
- end
169
- end
170
-
171
- # The connection should remain in tact
172
- assert_equal connections, redis.connections
173
- end
174
- end
175
-
176
- def test_shutdown_from_multi_exec
177
- commands = {
178
- :multi => lambda { "+OK\r\n" },
179
- :shutdown => lambda { "+QUEUED\r\n" },
180
- :exec => lambda { :exit }
181
- }
182
-
183
- redis_mock(commands) do |redis|
184
- result = redis.multi do
185
- redis.shutdown
186
- end
187
-
188
- assert_equal nil, result
189
- assert !redis._client.connected?
190
- end
191
- end
192
-
193
- def test_shutdown_with_error_from_multi_exec
194
- connections = 0
195
- commands = {
196
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
197
- :connections => lambda { ":#{connections}\r\n" },
198
- :multi => lambda { "+OK\r\n" },
199
- :shutdown => lambda { "+QUEUED\r\n" },
200
- :exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
201
- }
202
-
203
- redis_mock(commands) do |redis|
204
- connections = redis.connections
205
-
206
- # SHUTDOWN replies with an error: test that it gets returned
207
- # We should test for Redis::CommandError here, but hiredis doesn't yet do
208
- # custom error classes.
209
- err = nil
210
-
211
- begin
212
- redis.multi { redis.shutdown }
213
- rescue => err
214
- end
215
-
216
- assert err.kind_of?(StandardError)
217
-
218
- # The connection should remain intact
219
- assert_equal connections, redis.connections
220
- end
221
- end
222
-
223
- def test_slaveof
224
- redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do |redis|
225
- assert_equal "SLAVEOF somehost 6381", redis.slaveof("somehost", 6381)
226
- end
227
- end
228
-
229
- def test_bgrewriteaof
230
- redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do |redis|
231
- assert_equal "BGREWRITEAOF", redis.bgrewriteaof
232
- end
233
- end
234
-
235
- def test_config_get
236
- assert r.config(:get, "*")["timeout"] != nil
237
-
238
- config = r.config(:get, "timeout")
239
- assert_equal ["timeout"], config.keys
240
- assert config.values.compact.size > 0
241
- end
242
-
243
- def test_config_set
244
- begin
245
- assert_equal "OK", r.config(:set, "timeout", 200)
246
- assert_equal "200", r.config(:get, "*")["timeout"]
247
-
248
- assert_equal "OK", r.config(:set, "timeout", 100)
249
- assert_equal "100", r.config(:get, "*")["timeout"]
250
- ensure
251
- r.config :set, "timeout", 300
252
- end
253
- end
254
-
255
- driver(:ruby, :hiredis) do
256
- def test_consistency_on_multithreaded_env
257
- t = nil
258
-
259
- commands = {
260
- :set => lambda { |key, value| t.kill; "+OK\r\n" },
261
- :incr => lambda { |key| ":1\r\n" },
262
- }
263
-
264
- redis_mock(commands) do |redis|
265
- t = Thread.new do
266
- redis.set("foo", "bar")
267
- end
268
-
269
- t.join
270
-
271
- assert_equal 1, redis.incr("baz")
272
- end
273
- end
274
- end
275
- end