redis 3.3.5 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +32 -50
- data/CHANGELOG.md +7 -9
- data/Gemfile +0 -1
- data/README.md +31 -75
- data/benchmarking/logging.rb +1 -1
- data/lib/redis.rb +31 -35
- data/lib/redis/client.rb +13 -8
- data/lib/redis/connection.rb +2 -2
- data/lib/redis/connection/command_helper.rb +2 -8
- data/lib/redis/connection/hiredis.rb +2 -2
- data/lib/redis/connection/ruby.rb +7 -27
- data/lib/redis/connection/synchrony.rb +3 -3
- data/lib/redis/pipeline.rb +0 -6
- data/lib/redis/version.rb +1 -1
- data/makefile +42 -0
- data/redis.gemspec +4 -8
- data/test/bitpos_test.rb +13 -19
- data/test/blocking_commands_test.rb +147 -6
- data/test/client_test.rb +1 -1
- data/test/command_map_test.rb +3 -5
- data/test/commands_on_hashes_test.rb +158 -5
- data/test/commands_on_hyper_log_log_test.rb +55 -6
- data/test/commands_on_lists_test.rb +139 -5
- data/test/commands_on_sets_test.rb +136 -5
- data/test/commands_on_sorted_sets_test.rb +312 -5
- data/test/commands_on_strings_test.rb +243 -6
- data/test/commands_on_value_types_test.rb +120 -7
- data/test/connection_handling_test.rb +5 -7
- data/test/encoding_test.rb +4 -8
- data/test/error_replies_test.rb +2 -4
- data/test/fork_safety_test.rb +1 -6
- data/test/helper.rb +9 -62
- data/test/helper_test.rb +1 -3
- data/test/internals_test.rb +67 -49
- data/test/persistence_control_commands_test.rb +1 -3
- data/test/pipelining_commands_test.rb +4 -8
- data/test/publish_subscribe_test.rb +1 -3
- data/test/remote_server_control_commands_test.rb +61 -4
- data/test/scanning_test.rb +1 -7
- data/test/scripting_test.rb +1 -3
- data/test/sentinel_command_test.rb +1 -3
- data/test/sentinel_test.rb +1 -3
- data/test/sorting_test.rb +1 -3
- data/test/ssl_test.rb +45 -49
- data/test/support/connection/hiredis.rb +1 -1
- data/test/support/connection/ruby.rb +1 -1
- data/test/support/connection/synchrony.rb +1 -1
- data/test/synchrony_driver.rb +6 -9
- data/test/thread_safety_test.rb +1 -3
- data/test/transactions_test.rb +1 -3
- data/test/unknown_commands_test.rb +1 -3
- data/test/url_param_test.rb +44 -46
- metadata +31 -77
- data/Rakefile +0 -87
- data/examples/dist_redis.rb +0 -43
- data/lib/redis/distributed.rb +0 -873
- data/lib/redis/hash_ring.rb +0 -132
- data/test/connection_test.rb +0 -57
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -59
- data/test/distributed_commands_on_value_types_test.rb +0 -95
- data/test/distributed_commands_requiring_clustering_test.rb +0 -164
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -79
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -66
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/lint/blocking_commands.rb +0 -150
- data/test/lint/hashes.rb +0 -162
- data/test/lint/hyper_log_log.rb +0 -60
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -140
- data/test/lint/sorted_sets.rb +0 -316
- data/test/lint/strings.rb +0 -260
- data/test/lint/value_types.rb +0 -122
@@ -1,12 +1,125 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/value_types"
|
1
|
+
require_relative "helper"
|
5
2
|
|
6
3
|
class TestCommandsOnValueTypes < Test::Unit::TestCase
|
7
4
|
|
8
5
|
include Helper::Client
|
9
|
-
|
6
|
+
|
7
|
+
def test_exists
|
8
|
+
assert_equal false, r.exists("foo")
|
9
|
+
|
10
|
+
r.set("foo", "s1")
|
11
|
+
|
12
|
+
assert_equal true, r.exists("foo")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_type
|
16
|
+
assert_equal "none", r.type("foo")
|
17
|
+
|
18
|
+
r.set("foo", "s1")
|
19
|
+
|
20
|
+
assert_equal "string", r.type("foo")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_keys
|
24
|
+
r.set("f", "s1")
|
25
|
+
r.set("fo", "s2")
|
26
|
+
r.set("foo", "s3")
|
27
|
+
|
28
|
+
assert_equal ["f","fo", "foo"], r.keys("f*").sort
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_expire
|
32
|
+
r.set("foo", "s1")
|
33
|
+
assert r.expire("foo", 2)
|
34
|
+
assert_in_range 0..2, r.ttl("foo")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_pexpire
|
38
|
+
target_version "2.5.4" do
|
39
|
+
r.set("foo", "s1")
|
40
|
+
assert r.pexpire("foo", 2000)
|
41
|
+
assert_in_range 0..2, r.ttl("foo")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_expireat
|
46
|
+
r.set("foo", "s1")
|
47
|
+
assert r.expireat("foo", (Time.now + 2).to_i)
|
48
|
+
assert_in_range 0..2, r.ttl("foo")
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_pexpireat
|
52
|
+
target_version "2.5.4" do
|
53
|
+
r.set("foo", "s1")
|
54
|
+
assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)
|
55
|
+
assert_in_range 0..2, r.ttl("foo")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_persist
|
60
|
+
r.set("foo", "s1")
|
61
|
+
r.expire("foo", 1)
|
62
|
+
r.persist("foo")
|
63
|
+
|
64
|
+
assert(-1 == r.ttl("foo"))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_ttl
|
68
|
+
r.set("foo", "s1")
|
69
|
+
r.expire("foo", 2)
|
70
|
+
assert_in_range 0..2, r.ttl("foo")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_pttl
|
74
|
+
target_version "2.5.4" do
|
75
|
+
r.set("foo", "s1")
|
76
|
+
r.expire("foo", 2)
|
77
|
+
assert_in_range 1..2000, r.pttl("foo")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_dump_and_restore
|
82
|
+
target_version "2.5.7" do
|
83
|
+
r.set("foo", "a")
|
84
|
+
v = r.dump("foo")
|
85
|
+
r.del("foo")
|
86
|
+
|
87
|
+
assert r.restore("foo", 1000, v)
|
88
|
+
assert_equal "a", r.get("foo")
|
89
|
+
assert [0, 1].include? r.ttl("foo")
|
90
|
+
|
91
|
+
r.rpush("bar", ["b", "c", "d"])
|
92
|
+
w = r.dump("bar")
|
93
|
+
r.del("bar")
|
94
|
+
|
95
|
+
assert r.restore("bar", 1000, w)
|
96
|
+
assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
|
97
|
+
assert [0, 1].include? r.ttl("bar")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_move
|
102
|
+
r.select 14
|
103
|
+
r.flushdb
|
104
|
+
|
105
|
+
r.set "bar", "s3"
|
106
|
+
|
107
|
+
r.select 15
|
108
|
+
|
109
|
+
r.set "foo", "s1"
|
110
|
+
r.set "bar", "s2"
|
111
|
+
|
112
|
+
assert r.move("foo", 14)
|
113
|
+
assert_equal nil, r.get("foo")
|
114
|
+
|
115
|
+
assert !r.move("bar", 14)
|
116
|
+
assert_equal "s2", r.get("bar")
|
117
|
+
|
118
|
+
r.select 14
|
119
|
+
|
120
|
+
assert_equal "s1", r.get("foo")
|
121
|
+
assert_equal "s3", r.get("bar")
|
122
|
+
end
|
10
123
|
|
11
124
|
def test_del
|
12
125
|
r.set "foo", "s1"
|
@@ -111,8 +224,8 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
|
|
111
224
|
end
|
112
225
|
assert ex.message =~ /port not specified/
|
113
226
|
|
114
|
-
default_db = redis.
|
115
|
-
default_timeout = redis.
|
227
|
+
default_db = redis._client.db.to_i
|
228
|
+
default_timeout = redis._client.timeout.to_i
|
116
229
|
|
117
230
|
# Test defaults
|
118
231
|
actual = redis.migrate("foo", options)
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestConnectionHandling < Test::Unit::TestCase
|
6
4
|
|
@@ -40,7 +38,7 @@ class TestConnectionHandling < Test::Unit::TestCase
|
|
40
38
|
r.select 14
|
41
39
|
assert_equal nil, r.get("foo")
|
42
40
|
|
43
|
-
r.
|
41
|
+
r._client.disconnect
|
44
42
|
|
45
43
|
assert_equal nil, r.get("foo")
|
46
44
|
end
|
@@ -48,7 +46,7 @@ class TestConnectionHandling < Test::Unit::TestCase
|
|
48
46
|
def test_quit
|
49
47
|
r.quit
|
50
48
|
|
51
|
-
assert !r.
|
49
|
+
assert !r._client.connected?
|
52
50
|
end
|
53
51
|
|
54
52
|
def test_close
|
@@ -148,7 +146,7 @@ class TestConnectionHandling < Test::Unit::TestCase
|
|
148
146
|
end
|
149
147
|
|
150
148
|
assert_equal nil, result
|
151
|
-
assert !redis.
|
149
|
+
assert !redis._client.connected?
|
152
150
|
end
|
153
151
|
end
|
154
152
|
|
@@ -188,7 +186,7 @@ class TestConnectionHandling < Test::Unit::TestCase
|
|
188
186
|
end
|
189
187
|
|
190
188
|
assert_equal nil, result
|
191
|
-
assert !redis.
|
189
|
+
assert !redis._client.connected?
|
192
190
|
end
|
193
191
|
end
|
194
192
|
|
data/test/encoding_test.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestEncoding < Test::Unit::TestCase
|
6
4
|
|
7
5
|
include Helper::Client
|
8
6
|
|
9
7
|
def test_returns_properly_encoded_strings
|
10
|
-
|
11
|
-
|
12
|
-
r.set "foo", "שלום"
|
8
|
+
with_external_encoding("UTF-8") do
|
9
|
+
r.set "foo", "שלום"
|
13
10
|
|
14
|
-
|
15
|
-
end
|
11
|
+
assert_equal "Shalom שלום", "Shalom " + r.get("foo")
|
16
12
|
end
|
17
13
|
end
|
18
14
|
end
|
data/test/error_replies_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestErrorReplies < Test::Unit::TestCase
|
6
4
|
|
@@ -47,7 +45,7 @@ class TestErrorReplies < Test::Unit::TestCase
|
|
47
45
|
def test_recover_from_raise_in__call_loop
|
48
46
|
with_reconnection_check do
|
49
47
|
begin
|
50
|
-
r.
|
48
|
+
r._client.call_loop([:invalid_monitor]) do
|
51
49
|
assert false # Should never be executed
|
52
50
|
end
|
53
51
|
rescue => ex
|
data/test/fork_safety_test.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestForkSafety < Test::Unit::TestCase
|
6
4
|
|
7
5
|
include Helper::Client
|
8
|
-
include Helper::Skipable
|
9
6
|
|
10
7
|
driver(:ruby, :hiredis) do
|
11
8
|
def test_fork_safety
|
@@ -32,7 +29,6 @@ class TestForkSafety < Test::Unit::TestCase
|
|
32
29
|
|
33
30
|
rescue NotImplementedError => error
|
34
31
|
raise unless error.message =~ /fork is not available/
|
35
|
-
return skip(error.message)
|
36
32
|
end
|
37
33
|
|
38
34
|
def test_fork_safety_with_enabled_inherited_socket
|
@@ -59,7 +55,6 @@ class TestForkSafety < Test::Unit::TestCase
|
|
59
55
|
|
60
56
|
rescue NotImplementedError => error
|
61
57
|
raise unless error.message =~ /fork is not available/
|
62
|
-
return skip(error.message)
|
63
58
|
end
|
64
59
|
end
|
65
60
|
end
|
data/test/helper.rb
CHANGED
@@ -1,27 +1,16 @@
|
|
1
|
-
$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
2
|
-
$:.unshift File.expand_path(File.dirname(__FILE__))
|
3
|
-
|
4
1
|
require "test/unit"
|
5
2
|
require "logger"
|
6
3
|
require "stringio"
|
7
4
|
|
8
|
-
(class Random; def self.rand(*args) super end; end) unless defined?(Random)
|
9
|
-
|
10
|
-
begin
|
11
|
-
require "ruby-debug"
|
12
|
-
rescue LoadError
|
13
|
-
end
|
14
|
-
|
15
5
|
$VERBOSE = true
|
16
6
|
|
17
|
-
ENV["
|
7
|
+
ENV["DRIVER"] ||= "ruby"
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
require "redis/connection/#{ENV["conn"]}"
|
9
|
+
require_relative "../lib/redis"
|
10
|
+
require_relative "../lib/redis/connection/#{ENV["DRIVER"]}"
|
22
11
|
|
23
|
-
|
24
|
-
|
12
|
+
require_relative "support/redis_mock"
|
13
|
+
require_relative "support/connection/#{ENV["DRIVER"]}"
|
25
14
|
|
26
15
|
PORT = 6381
|
27
16
|
OPTIONS = {:port => PORT, :db => 15, :timeout => Float(ENV["TIMEOUT"] || 0.1)}
|
@@ -44,11 +33,11 @@ def init(redis)
|
|
44
33
|
|
45
34
|
Try this once:
|
46
35
|
|
47
|
-
$
|
36
|
+
$ make clean
|
48
37
|
|
49
38
|
Then run the build again:
|
50
39
|
|
51
|
-
$
|
40
|
+
$ make
|
52
41
|
|
53
42
|
EOS
|
54
43
|
exit 1
|
@@ -56,7 +45,7 @@ def init(redis)
|
|
56
45
|
end
|
57
46
|
|
58
47
|
def driver(*drivers, &blk)
|
59
|
-
if drivers.map(&:to_s).include?(ENV["
|
48
|
+
if drivers.map(&:to_s).include?(ENV["DRIVER"])
|
60
49
|
class_eval(&blk)
|
61
50
|
end
|
62
51
|
end
|
@@ -92,14 +81,6 @@ module Helper
|
|
92
81
|
end
|
93
82
|
end
|
94
83
|
|
95
|
-
def try_encoding(encoding, &block)
|
96
|
-
if defined?(Encoding)
|
97
|
-
with_external_encoding(encoding, &block)
|
98
|
-
else
|
99
|
-
yield
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
84
|
class Version
|
104
85
|
|
105
86
|
include Comparable
|
@@ -191,42 +172,8 @@ module Helper
|
|
191
172
|
end
|
192
173
|
|
193
174
|
def _new_client(options = {})
|
194
|
-
Redis.new(_format_options(options).merge(:driver => ENV["
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
module Distributed
|
199
|
-
|
200
|
-
include Generic
|
201
|
-
|
202
|
-
def version
|
203
|
-
Version.new(redis.info.first["redis_version"])
|
204
|
-
end
|
205
|
-
|
206
|
-
private
|
207
|
-
|
208
|
-
def _format_options(options)
|
209
|
-
{
|
210
|
-
:timeout => OPTIONS[:timeout],
|
211
|
-
:logger => ::Logger.new(@log),
|
212
|
-
}.merge(options)
|
213
|
-
end
|
214
|
-
|
215
|
-
def _new_client(options = {})
|
216
|
-
Redis::Distributed.new(NODES, _format_options(options).merge(:driver => ENV["conn"]))
|
175
|
+
Redis.new(_format_options(options).merge(:driver => ENV["DRIVER"]))
|
217
176
|
end
|
218
177
|
end
|
219
178
|
|
220
|
-
# Basic support for `skip` in 1.8.x
|
221
|
-
# Note: YOU MUST use `return skip(message)` in order to appropriately bail
|
222
|
-
# from a running test.
|
223
|
-
module Skipable
|
224
|
-
Skipped = Class.new(RuntimeError)
|
225
|
-
|
226
|
-
def skip(message = nil, bt = caller)
|
227
|
-
return super if defined?(super)
|
228
|
-
|
229
|
-
$stderr.puts("SKIPPED: #{self} #{message || 'no reason given'}")
|
230
|
-
end
|
231
|
-
end
|
232
179
|
end
|
data/test/helper_test.rb
CHANGED
data/test/internals_test.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
1
|
+
require_relative "helper"
|
4
2
|
|
5
3
|
class TestInternals < Test::Unit::TestCase
|
6
4
|
|
7
5
|
include Helper::Client
|
8
|
-
include Helper::Skipable
|
9
6
|
|
10
7
|
def test_logger
|
11
8
|
r.ping
|
@@ -44,24 +41,28 @@ class TestInternals < Test::Unit::TestCase
|
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
44
|
+
def test_provides_a_meaningful_inspect
|
45
|
+
assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
|
46
|
+
end
|
47
|
+
|
47
48
|
def test_redis_current
|
48
|
-
assert_equal "127.0.0.1", Redis.current.
|
49
|
-
assert_equal 6379, Redis.current.
|
50
|
-
assert_equal 0, Redis.current.
|
49
|
+
assert_equal "127.0.0.1", Redis.current._client.host
|
50
|
+
assert_equal 6379, Redis.current._client.port
|
51
|
+
assert_equal 0, Redis.current._client.db
|
51
52
|
|
52
53
|
Redis.current = Redis.new(OPTIONS.merge(:port => 6380, :db => 1))
|
53
54
|
|
54
55
|
t = Thread.new do
|
55
|
-
assert_equal "127.0.0.1", Redis.current.
|
56
|
-
assert_equal 6380, Redis.current.
|
57
|
-
assert_equal 1, Redis.current.
|
56
|
+
assert_equal "127.0.0.1", Redis.current._client.host
|
57
|
+
assert_equal 6380, Redis.current._client.port
|
58
|
+
assert_equal 1, Redis.current._client.db
|
58
59
|
end
|
59
60
|
|
60
61
|
t.join
|
61
62
|
|
62
|
-
assert_equal "127.0.0.1", Redis.current.
|
63
|
-
assert_equal 6380, Redis.current.
|
64
|
-
assert_equal 1, Redis.current.
|
63
|
+
assert_equal "127.0.0.1", Redis.current._client.host
|
64
|
+
assert_equal 6380, Redis.current._client.port
|
65
|
+
assert_equal 1, Redis.current._client.db
|
65
66
|
end
|
66
67
|
|
67
68
|
def test_redis_connected?
|
@@ -75,12 +76,48 @@ class TestInternals < Test::Unit::TestCase
|
|
75
76
|
assert !fresh_client.connected?
|
76
77
|
end
|
77
78
|
|
79
|
+
def test_default_id_with_host_and_port
|
80
|
+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
|
81
|
+
assert_equal "redis://host:1234/0", redis._client.id
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_default_id_with_host_and_port_and_explicit_scheme
|
85
|
+
redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
|
86
|
+
assert_equal "redis://host:1234/0", redis._client.id
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_default_id_with_path
|
90
|
+
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
|
91
|
+
assert_equal "redis:///tmp/redis.sock/0", redis._client.id
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_default_id_with_path_and_explicit_scheme
|
95
|
+
redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
|
96
|
+
assert_equal "redis:///tmp/redis.sock/0", redis._client.id
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_override_id
|
100
|
+
redis = Redis.new(OPTIONS.merge(:id => "test"))
|
101
|
+
assert_equal redis._client.id, "test"
|
102
|
+
end
|
103
|
+
|
78
104
|
def test_timeout
|
79
105
|
assert_nothing_raised do
|
80
106
|
Redis.new(OPTIONS.merge(:timeout => 0))
|
81
107
|
end
|
82
108
|
end
|
83
109
|
|
110
|
+
def test_id_inside_multi
|
111
|
+
redis = Redis.new(OPTIONS)
|
112
|
+
id = nil
|
113
|
+
|
114
|
+
redis.multi do
|
115
|
+
id = redis.id
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal id, "redis://127.0.0.1:6381/15"
|
119
|
+
end
|
120
|
+
|
84
121
|
driver(:ruby) do
|
85
122
|
def test_tcp_keepalive
|
86
123
|
keepalive = {:time => 20, :intvl => 10, :probes => 5}
|
@@ -88,7 +125,7 @@ class TestInternals < Test::Unit::TestCase
|
|
88
125
|
redis = Redis.new(OPTIONS.merge(:tcp_keepalive => keepalive))
|
89
126
|
redis.ping
|
90
127
|
|
91
|
-
connection = redis.
|
128
|
+
connection = redis._client.connection
|
92
129
|
actual_keepalive = connection.get_tcp_keepalive
|
93
130
|
|
94
131
|
[:time, :intvl, :probes].each do |key|
|
@@ -121,25 +158,6 @@ class TestInternals < Test::Unit::TestCase
|
|
121
158
|
assert (Time.now - start_time) <= opts[:timeout]
|
122
159
|
end
|
123
160
|
|
124
|
-
driver(:ruby) do
|
125
|
-
def test_write_timeout
|
126
|
-
return skip("Relies on buffer sizes, might be unreliable")
|
127
|
-
|
128
|
-
server = TCPServer.new("127.0.0.1", 0)
|
129
|
-
port = server.addr[1]
|
130
|
-
|
131
|
-
# Hacky, but we need the buffer size
|
132
|
-
val = TCPSocket.new("127.0.0.1", port).getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).unpack("i")[0]
|
133
|
-
|
134
|
-
assert_raise(Redis::TimeoutError) do
|
135
|
-
Timeout.timeout(1) do
|
136
|
-
redis = Redis.new(:port => port, :timeout => 5, :write_timeout => 0.1)
|
137
|
-
redis.set("foo", "1" * val*2)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
161
|
def close_on_ping(seq, options = {})
|
144
162
|
$request = 0
|
145
163
|
|
@@ -197,7 +215,7 @@ class TestInternals < Test::Unit::TestCase
|
|
197
215
|
redis.ping
|
198
216
|
end
|
199
217
|
|
200
|
-
assert !redis.
|
218
|
+
assert !redis._client.connected?
|
201
219
|
end
|
202
220
|
end
|
203
221
|
|
@@ -213,7 +231,7 @@ class TestInternals < Test::Unit::TestCase
|
|
213
231
|
redis.ping
|
214
232
|
end
|
215
233
|
|
216
|
-
assert !redis.
|
234
|
+
assert !redis._client.connected?
|
217
235
|
end
|
218
236
|
end
|
219
237
|
|
@@ -226,7 +244,7 @@ class TestInternals < Test::Unit::TestCase
|
|
226
244
|
end
|
227
245
|
end
|
228
246
|
|
229
|
-
assert !redis.
|
247
|
+
assert !redis._client.connected?
|
230
248
|
end
|
231
249
|
end
|
232
250
|
|
@@ -267,14 +285,14 @@ class TestInternals < Test::Unit::TestCase
|
|
267
285
|
|
268
286
|
def test_retry_on_write_error_by_default
|
269
287
|
close_on_connection([0]) do |redis|
|
270
|
-
assert_equal "1", redis.
|
288
|
+
assert_equal "1", redis._client.call(["x" * 128 * 1024])
|
271
289
|
end
|
272
290
|
end
|
273
291
|
|
274
292
|
def test_retry_on_write_error_when_wrapped_in_with_reconnect_true
|
275
293
|
close_on_connection([0]) do |redis|
|
276
294
|
redis.with_reconnect(true) do
|
277
|
-
assert_equal "1", redis.
|
295
|
+
assert_equal "1", redis._client.call(["x" * 128 * 1024])
|
278
296
|
end
|
279
297
|
end
|
280
298
|
end
|
@@ -283,7 +301,7 @@ class TestInternals < Test::Unit::TestCase
|
|
283
301
|
close_on_connection([0]) do |redis|
|
284
302
|
assert_raise Redis::ConnectionError do
|
285
303
|
redis.with_reconnect(false) do
|
286
|
-
redis.
|
304
|
+
redis._client.call(["x" * 128 * 1024])
|
287
305
|
end
|
288
306
|
end
|
289
307
|
end
|
@@ -293,7 +311,7 @@ class TestInternals < Test::Unit::TestCase
|
|
293
311
|
close_on_connection([0]) do |redis|
|
294
312
|
assert_raise Redis::ConnectionError do
|
295
313
|
redis.without_reconnect do
|
296
|
-
redis.
|
314
|
+
redis._client.call(["x" * 128 * 1024])
|
297
315
|
end
|
298
316
|
end
|
299
317
|
end
|
@@ -301,7 +319,7 @@ class TestInternals < Test::Unit::TestCase
|
|
301
319
|
|
302
320
|
def test_connecting_to_unix_domain_socket
|
303
321
|
assert_nothing_raised do
|
304
|
-
Redis.new(OPTIONS.merge(:path =>
|
322
|
+
Redis.new(OPTIONS.merge(:path => ENV.fetch("SOCKET_PATH"))).ping
|
305
323
|
end
|
306
324
|
end
|
307
325
|
|
@@ -323,23 +341,23 @@ class TestInternals < Test::Unit::TestCase
|
|
323
341
|
def test_client_options
|
324
342
|
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
|
325
343
|
|
326
|
-
assert_equal "host", redis.
|
327
|
-
assert_equal 1234, redis.
|
328
|
-
assert_equal 1, redis.
|
329
|
-
assert_equal "foo", redis.
|
344
|
+
assert_equal "host", redis._client.options[:host]
|
345
|
+
assert_equal 1234, redis._client.options[:port]
|
346
|
+
assert_equal 1, redis._client.options[:db]
|
347
|
+
assert_equal "foo", redis._client.options[:scheme]
|
330
348
|
end
|
331
349
|
|
332
350
|
def test_does_not_change_self_client_options
|
333
351
|
redis = Redis.new(OPTIONS.merge(:host => "host", :port => 1234, :db => 1, :scheme => "foo"))
|
334
|
-
options = redis.
|
352
|
+
options = redis._client.options
|
335
353
|
|
336
354
|
options[:host] << "new_host"
|
337
355
|
options[:scheme] << "bar"
|
338
356
|
options.merge!(:db => 0)
|
339
357
|
|
340
|
-
assert_equal "host", redis.
|
341
|
-
assert_equal 1, redis.
|
342
|
-
assert_equal "foo", redis.
|
358
|
+
assert_equal "host", redis._client.options[:host]
|
359
|
+
assert_equal 1, redis._client.options[:db]
|
360
|
+
assert_equal "foo", redis._client.options[:scheme]
|
343
361
|
end
|
344
362
|
|
345
363
|
def test_resolves_localhost
|