redis 3.3.5 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +132 -2
- data/README.md +144 -79
- data/lib/redis.rb +1174 -405
- data/lib/redis/client.rb +150 -90
- data/lib/redis/cluster.rb +295 -0
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +34 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +107 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +37 -0
- data/lib/redis/cluster/option.rb +93 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +49 -0
- data/lib/redis/connection.rb +4 -2
- data/lib/redis/connection/command_helper.rb +5 -10
- data/lib/redis/connection/hiredis.rb +6 -5
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +126 -128
- data/lib/redis/connection/synchrony.rb +21 -8
- data/lib/redis/distributed.rb +147 -72
- data/lib/redis/errors.rb +48 -0
- data/lib/redis/hash_ring.rb +30 -73
- data/lib/redis/pipeline.rb +55 -15
- data/lib/redis/subscribe.rb +11 -12
- data/lib/redis/version.rb +3 -1
- metadata +49 -202
- data/.gitignore +0 -16
- data/.travis.yml +0 -89
- data/.travis/Gemfile +0 -11
- data/.yardopts +0 -3
- data/Gemfile +0 -4
- data/Rakefile +0 -87
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel.rb +0 -41
- data/examples/sentinel/sentinel.conf +0 -9
- data/examples/sentinel/start +0 -49
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/redis.gemspec +0 -44
- data/test/bitpos_test.rb +0 -69
- data/test/blocking_commands_test.rb +0 -42
- data/test/client_test.rb +0 -59
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_hyper_log_log_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -137
- data/test/commands_on_strings_test.rb +0 -101
- data/test/commands_on_value_types_test.rb +0 -133
- data/test/connection_handling_test.rb +0 -277
- data/test/connection_test.rb +0 -57
- data/test/db/.gitkeep +0 -0
- 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/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/fork_safety_test.rb +0 -65
- data/test/helper.rb +0 -232
- data/test/helper_test.rb +0 -24
- data/test/internals_test.rb +0 -417
- 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
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -242
- data/test/publish_subscribe_test.rb +0 -282
- data/test/remote_server_control_commands_test.rb +0 -118
- data/test/scanning_test.rb +0 -413
- data/test/scripting_test.rb +0 -78
- data/test/sentinel_command_test.rb +0 -80
- data/test/sentinel_test.rb +0 -255
- data/test/sorting_test.rb +0 -59
- data/test/ssl_test.rb +0 -73
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -88
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -62
- data/test/transactions_test.rb +0 -264
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -138
@@ -1,101 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/strings"
|
5
|
-
|
6
|
-
class TestCommandsOnStrings < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::Strings
|
10
|
-
|
11
|
-
def test_mget
|
12
|
-
r.set("foo", "s1")
|
13
|
-
r.set("bar", "s2")
|
14
|
-
|
15
|
-
assert_equal ["s1", "s2"] , r.mget("foo", "bar")
|
16
|
-
assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_mget_mapped
|
20
|
-
r.set("foo", "s1")
|
21
|
-
r.set("bar", "s2")
|
22
|
-
|
23
|
-
response = r.mapped_mget("foo", "bar")
|
24
|
-
|
25
|
-
assert_equal "s1", response["foo"]
|
26
|
-
assert_equal "s2", response["bar"]
|
27
|
-
|
28
|
-
response = r.mapped_mget("foo", "bar", "baz")
|
29
|
-
|
30
|
-
assert_equal "s1", response["foo"]
|
31
|
-
assert_equal "s2", response["bar"]
|
32
|
-
assert_equal nil , response["baz"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_mapped_mget_in_a_pipeline_returns_hash
|
36
|
-
r.set("foo", "s1")
|
37
|
-
r.set("bar", "s2")
|
38
|
-
|
39
|
-
result = r.pipelined do
|
40
|
-
r.mapped_mget("foo", "bar")
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_mset
|
47
|
-
r.mset(:foo, "s1", :bar, "s2")
|
48
|
-
|
49
|
-
assert_equal "s1", r.get("foo")
|
50
|
-
assert_equal "s2", r.get("bar")
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mset_mapped
|
54
|
-
r.mapped_mset(:foo => "s1", :bar => "s2")
|
55
|
-
|
56
|
-
assert_equal "s1", r.get("foo")
|
57
|
-
assert_equal "s2", r.get("bar")
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_msetnx
|
61
|
-
r.set("foo", "s1")
|
62
|
-
assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
|
63
|
-
assert_equal "s1", r.get("foo")
|
64
|
-
assert_equal nil, r.get("bar")
|
65
|
-
|
66
|
-
r.del("foo")
|
67
|
-
assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
|
68
|
-
assert_equal "s2", r.get("foo")
|
69
|
-
assert_equal "s3", r.get("bar")
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_msetnx_mapped
|
73
|
-
r.set("foo", "s1")
|
74
|
-
assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
75
|
-
assert_equal "s1", r.get("foo")
|
76
|
-
assert_equal nil, r.get("bar")
|
77
|
-
|
78
|
-
r.del("foo")
|
79
|
-
assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
80
|
-
assert_equal "s2", r.get("foo")
|
81
|
-
assert_equal "s3", r.get("bar")
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_bitop
|
85
|
-
try_encoding("UTF-8") do
|
86
|
-
target_version "2.5.10" do
|
87
|
-
r.set("foo", "a")
|
88
|
-
r.set("bar", "b")
|
89
|
-
|
90
|
-
r.bitop(:and, "foo&bar", "foo", "bar")
|
91
|
-
assert_equal "\x60", r.get("foo&bar")
|
92
|
-
r.bitop(:or, "foo|bar", "foo", "bar")
|
93
|
-
assert_equal "\x63", r.get("foo|bar")
|
94
|
-
r.bitop(:xor, "foo^bar", "foo", "bar")
|
95
|
-
assert_equal "\x03", r.get("foo^bar")
|
96
|
-
r.bitop(:not, "~foo", "foo")
|
97
|
-
assert_equal "\x9E", r.get("~foo")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
require "lint/value_types"
|
5
|
-
|
6
|
-
class TestCommandsOnValueTypes < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::ValueTypes
|
10
|
-
|
11
|
-
def test_del
|
12
|
-
r.set "foo", "s1"
|
13
|
-
r.set "bar", "s2"
|
14
|
-
r.set "baz", "s3"
|
15
|
-
|
16
|
-
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
17
|
-
|
18
|
-
assert_equal 1, r.del("foo")
|
19
|
-
|
20
|
-
assert_equal ["bar", "baz"], r.keys("*").sort
|
21
|
-
|
22
|
-
assert_equal 2, r.del("bar", "baz")
|
23
|
-
|
24
|
-
assert_equal [], r.keys("*").sort
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_del_with_array_argument
|
28
|
-
r.set "foo", "s1"
|
29
|
-
r.set "bar", "s2"
|
30
|
-
r.set "baz", "s3"
|
31
|
-
|
32
|
-
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
33
|
-
|
34
|
-
assert_equal 1, r.del(["foo"])
|
35
|
-
|
36
|
-
assert_equal ["bar", "baz"], r.keys("*").sort
|
37
|
-
|
38
|
-
assert_equal 2, r.del(["bar", "baz"])
|
39
|
-
|
40
|
-
assert_equal [], r.keys("*").sort
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_randomkey
|
44
|
-
assert r.randomkey.to_s.empty?
|
45
|
-
|
46
|
-
r.set("foo", "s1")
|
47
|
-
|
48
|
-
assert_equal "foo", r.randomkey
|
49
|
-
|
50
|
-
r.set("bar", "s2")
|
51
|
-
|
52
|
-
4.times do
|
53
|
-
assert ["foo", "bar"].include?(r.randomkey)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_rename
|
58
|
-
r.set("foo", "s1")
|
59
|
-
r.rename "foo", "bar"
|
60
|
-
|
61
|
-
assert_equal "s1", r.get("bar")
|
62
|
-
assert_equal nil, r.get("foo")
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_renamenx
|
66
|
-
r.set("foo", "s1")
|
67
|
-
r.set("bar", "s2")
|
68
|
-
|
69
|
-
assert_equal false, r.renamenx("foo", "bar")
|
70
|
-
|
71
|
-
assert_equal "s1", r.get("foo")
|
72
|
-
assert_equal "s2", r.get("bar")
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_dbsize
|
76
|
-
assert_equal 0, r.dbsize
|
77
|
-
|
78
|
-
r.set("foo", "s1")
|
79
|
-
|
80
|
-
assert_equal 1, r.dbsize
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_flushdb
|
84
|
-
r.set("foo", "s1")
|
85
|
-
r.set("bar", "s2")
|
86
|
-
|
87
|
-
assert_equal 2, r.dbsize
|
88
|
-
|
89
|
-
r.flushdb
|
90
|
-
|
91
|
-
assert_equal 0, r.dbsize
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_flushall
|
95
|
-
redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
|
96
|
-
assert_equal "FLUSHALL", redis.flushall
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_migrate
|
101
|
-
redis_mock(:migrate => lambda { |*args| args }) do |redis|
|
102
|
-
options = { :host => "127.0.0.1", :port => 1234 }
|
103
|
-
|
104
|
-
ex = assert_raise(RuntimeError) do
|
105
|
-
redis.migrate("foo", options.reject { |key, _| key == :host })
|
106
|
-
end
|
107
|
-
assert ex.message =~ /host not specified/
|
108
|
-
|
109
|
-
ex = assert_raise(RuntimeError) do
|
110
|
-
redis.migrate("foo", options.reject { |key, _| key == :port })
|
111
|
-
end
|
112
|
-
assert ex.message =~ /port not specified/
|
113
|
-
|
114
|
-
default_db = redis.client.db.to_i
|
115
|
-
default_timeout = redis.client.timeout.to_i
|
116
|
-
|
117
|
-
# Test defaults
|
118
|
-
actual = redis.migrate("foo", options)
|
119
|
-
expected = ["127.0.0.1", "1234", "foo", default_db.to_s, default_timeout.to_s]
|
120
|
-
assert_equal expected, actual
|
121
|
-
|
122
|
-
# Test db override
|
123
|
-
actual = redis.migrate("foo", options.merge(:db => default_db + 1))
|
124
|
-
expected = ["127.0.0.1", "1234", "foo", (default_db + 1).to_s, default_timeout.to_s]
|
125
|
-
assert_equal expected, actual
|
126
|
-
|
127
|
-
# Test timeout override
|
128
|
-
actual = redis.migrate("foo", options.merge(:timeout => default_timeout + 1))
|
129
|
-
expected = ["127.0.0.1", "1234", "foo", default_db.to_s, (default_timeout + 1).to_s]
|
130
|
-
assert_equal expected, actual
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,277 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class TestConnectionHandling < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Client
|
8
|
-
|
9
|
-
def test_auth
|
10
|
-
commands = {
|
11
|
-
:auth => lambda { |password| $auth = password; "+OK" },
|
12
|
-
:get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
|
13
|
-
}
|
14
|
-
|
15
|
-
redis_mock(commands, :password => "secret") do |redis|
|
16
|
-
assert_equal "bar", redis.get("foo")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_id
|
21
|
-
commands = {
|
22
|
-
:client => lambda { |cmd, name| $name = [cmd, name]; "+OK" },
|
23
|
-
:ping => lambda { "+PONG" },
|
24
|
-
}
|
25
|
-
|
26
|
-
redis_mock(commands, :id => "client-name") do |redis|
|
27
|
-
assert_equal "PONG", redis.ping
|
28
|
-
end
|
29
|
-
|
30
|
-
assert_equal ["setname","client-name"], $name
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_ping
|
34
|
-
assert_equal "PONG", r.ping
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_select
|
38
|
-
r.set "foo", "bar"
|
39
|
-
|
40
|
-
r.select 14
|
41
|
-
assert_equal nil, r.get("foo")
|
42
|
-
|
43
|
-
r.client.disconnect
|
44
|
-
|
45
|
-
assert_equal nil, r.get("foo")
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_quit
|
49
|
-
r.quit
|
50
|
-
|
51
|
-
assert !r.client.connected?
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_close
|
55
|
-
quit = 0
|
56
|
-
|
57
|
-
commands = {
|
58
|
-
:quit => lambda do
|
59
|
-
quit += 1
|
60
|
-
"+OK"
|
61
|
-
end
|
62
|
-
}
|
63
|
-
|
64
|
-
redis_mock(commands) do |redis|
|
65
|
-
assert_equal 0, quit
|
66
|
-
|
67
|
-
redis.quit
|
68
|
-
|
69
|
-
assert_equal 1, quit
|
70
|
-
|
71
|
-
redis.ping
|
72
|
-
|
73
|
-
redis.close
|
74
|
-
|
75
|
-
assert_equal 1, quit
|
76
|
-
|
77
|
-
assert !redis.connected?
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_disconnect
|
82
|
-
quit = 0
|
83
|
-
|
84
|
-
commands = {
|
85
|
-
:quit => lambda do
|
86
|
-
quit += 1
|
87
|
-
"+OK"
|
88
|
-
end
|
89
|
-
}
|
90
|
-
|
91
|
-
redis_mock(commands) do |redis|
|
92
|
-
assert_equal 0, quit
|
93
|
-
|
94
|
-
redis.quit
|
95
|
-
|
96
|
-
assert_equal 1, quit
|
97
|
-
|
98
|
-
redis.ping
|
99
|
-
|
100
|
-
redis.disconnect!
|
101
|
-
|
102
|
-
assert_equal 1, quit
|
103
|
-
|
104
|
-
assert !redis.connected?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_shutdown
|
109
|
-
commands = {
|
110
|
-
:shutdown => lambda { :exit }
|
111
|
-
}
|
112
|
-
|
113
|
-
redis_mock(commands) do |redis|
|
114
|
-
# SHUTDOWN does not reply: test that it does not raise here.
|
115
|
-
assert_equal nil, redis.shutdown
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_shutdown_with_error
|
120
|
-
connections = 0
|
121
|
-
commands = {
|
122
|
-
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
123
|
-
:connections => lambda { ":#{connections}\r\n" },
|
124
|
-
:shutdown => lambda { "-ERR could not shutdown\r\n" }
|
125
|
-
}
|
126
|
-
|
127
|
-
redis_mock(commands) do |redis|
|
128
|
-
connections = redis.connections
|
129
|
-
|
130
|
-
# SHUTDOWN replies with an error: test that it gets raised
|
131
|
-
assert_raise Redis::CommandError do
|
132
|
-
redis.shutdown
|
133
|
-
end
|
134
|
-
|
135
|
-
# The connection should remain in tact
|
136
|
-
assert_equal connections, redis.connections
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_shutdown_from_pipeline
|
141
|
-
commands = {
|
142
|
-
:shutdown => lambda { :exit }
|
143
|
-
}
|
144
|
-
|
145
|
-
redis_mock(commands) do |redis|
|
146
|
-
result = redis.pipelined do
|
147
|
-
redis.shutdown
|
148
|
-
end
|
149
|
-
|
150
|
-
assert_equal nil, result
|
151
|
-
assert !redis.client.connected?
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_shutdown_with_error_from_pipeline
|
156
|
-
connections = 0
|
157
|
-
commands = {
|
158
|
-
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
159
|
-
:connections => lambda { ":#{connections}\r\n" },
|
160
|
-
:shutdown => lambda { "-ERR could not shutdown\r\n" }
|
161
|
-
}
|
162
|
-
|
163
|
-
redis_mock(commands) do |redis|
|
164
|
-
connections = redis.connections
|
165
|
-
|
166
|
-
# SHUTDOWN replies with an error: test that it gets raised
|
167
|
-
assert_raise Redis::CommandError do
|
168
|
-
redis.pipelined do
|
169
|
-
redis.shutdown
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# The connection should remain in tact
|
174
|
-
assert_equal connections, redis.connections
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_shutdown_from_multi_exec
|
179
|
-
commands = {
|
180
|
-
:multi => lambda { "+OK\r\n" },
|
181
|
-
:shutdown => lambda { "+QUEUED\r\n" },
|
182
|
-
:exec => lambda { :exit }
|
183
|
-
}
|
184
|
-
|
185
|
-
redis_mock(commands) do |redis|
|
186
|
-
result = redis.multi do
|
187
|
-
redis.shutdown
|
188
|
-
end
|
189
|
-
|
190
|
-
assert_equal nil, result
|
191
|
-
assert !redis.client.connected?
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_shutdown_with_error_from_multi_exec
|
196
|
-
connections = 0
|
197
|
-
commands = {
|
198
|
-
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
199
|
-
:connections => lambda { ":#{connections}\r\n" },
|
200
|
-
:multi => lambda { "+OK\r\n" },
|
201
|
-
:shutdown => lambda { "+QUEUED\r\n" },
|
202
|
-
:exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
|
203
|
-
}
|
204
|
-
|
205
|
-
redis_mock(commands) do |redis|
|
206
|
-
connections = redis.connections
|
207
|
-
|
208
|
-
# SHUTDOWN replies with an error: test that it gets returned
|
209
|
-
# We should test for Redis::CommandError here, but hiredis doesn't yet do
|
210
|
-
# custom error classes.
|
211
|
-
err = nil
|
212
|
-
|
213
|
-
begin
|
214
|
-
redis.multi { redis.shutdown }
|
215
|
-
rescue => err
|
216
|
-
end
|
217
|
-
|
218
|
-
assert err.kind_of?(StandardError)
|
219
|
-
|
220
|
-
# The connection should remain intact
|
221
|
-
assert_equal connections, redis.connections
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def test_slaveof
|
226
|
-
redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do |redis|
|
227
|
-
assert_equal "SLAVEOF somehost 6381", redis.slaveof("somehost", 6381)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def test_bgrewriteaof
|
232
|
-
redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do |redis|
|
233
|
-
assert_equal "BGREWRITEAOF", redis.bgrewriteaof
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_config_get
|
238
|
-
assert r.config(:get, "*")["timeout"] != nil
|
239
|
-
|
240
|
-
config = r.config(:get, "timeout")
|
241
|
-
assert_equal ["timeout"], config.keys
|
242
|
-
assert config.values.compact.size > 0
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_config_set
|
246
|
-
begin
|
247
|
-
assert_equal "OK", r.config(:set, "timeout", 200)
|
248
|
-
assert_equal "200", r.config(:get, "*")["timeout"]
|
249
|
-
|
250
|
-
assert_equal "OK", r.config(:set, "timeout", 100)
|
251
|
-
assert_equal "100", r.config(:get, "*")["timeout"]
|
252
|
-
ensure
|
253
|
-
r.config :set, "timeout", 300
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
driver(:ruby, :hiredis) do
|
258
|
-
def test_consistency_on_multithreaded_env
|
259
|
-
t = nil
|
260
|
-
|
261
|
-
commands = {
|
262
|
-
:set => lambda { |key, value| t.kill; "+OK\r\n" },
|
263
|
-
:incr => lambda { |key| ":1\r\n" },
|
264
|
-
}
|
265
|
-
|
266
|
-
redis_mock(commands) do |redis|
|
267
|
-
t = Thread.new do
|
268
|
-
redis.set("foo", "bar")
|
269
|
-
end
|
270
|
-
|
271
|
-
t.join
|
272
|
-
|
273
|
-
assert_equal 1, redis.incr("baz")
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|