redis 3.0.0.rc1 → 3.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +50 -0
- data/.travis/Gemfile +11 -0
- data/CHANGELOG.md +47 -19
- data/README.md +160 -149
- data/Rakefile +15 -50
- data/examples/pubsub.rb +1 -1
- data/examples/unicorn/config.ru +1 -1
- data/examples/unicorn/unicorn.rb +1 -1
- data/lib/redis.rb +790 -390
- data/lib/redis/client.rb +137 -49
- data/lib/redis/connection/hiredis.rb +26 -15
- data/lib/redis/connection/ruby.rb +170 -53
- data/lib/redis/connection/synchrony.rb +23 -35
- data/lib/redis/distributed.rb +92 -32
- data/lib/redis/errors.rb +4 -2
- data/lib/redis/pipeline.rb +17 -6
- data/lib/redis/version.rb +1 -1
- data/redis.gemspec +4 -6
- data/test/blocking_commands_test.rb +42 -0
- data/test/command_map_test.rb +18 -17
- data/test/commands_on_hashes_test.rb +13 -12
- data/test/commands_on_lists_test.rb +35 -45
- data/test/commands_on_sets_test.rb +55 -54
- data/test/commands_on_sorted_sets_test.rb +106 -105
- data/test/commands_on_strings_test.rb +64 -55
- data/test/commands_on_value_types_test.rb +66 -54
- data/test/connection_handling_test.rb +136 -151
- data/test/distributed_blocking_commands_test.rb +33 -40
- data/test/distributed_commands_on_hashes_test.rb +6 -7
- data/test/distributed_commands_on_lists_test.rb +13 -14
- data/test/distributed_commands_on_sets_test.rb +57 -58
- data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
- data/test/distributed_commands_on_strings_test.rb +31 -32
- data/test/distributed_commands_on_value_types_test.rb +61 -46
- data/test/distributed_commands_requiring_clustering_test.rb +108 -108
- data/test/distributed_connection_handling_test.rb +14 -15
- data/test/distributed_internals_test.rb +7 -19
- data/test/distributed_key_tags_test.rb +36 -36
- data/test/distributed_persistence_control_commands_test.rb +17 -14
- data/test/distributed_publish_subscribe_test.rb +61 -69
- data/test/distributed_remote_server_control_commands_test.rb +39 -28
- data/test/distributed_sorting_test.rb +12 -13
- data/test/distributed_test.rb +40 -41
- data/test/distributed_transactions_test.rb +20 -21
- data/test/encoding_test.rb +12 -9
- data/test/error_replies_test.rb +42 -36
- data/test/helper.rb +118 -85
- data/test/helper_test.rb +20 -6
- data/test/internals_test.rb +167 -103
- data/test/lint/blocking_commands.rb +124 -0
- data/test/lint/hashes.rb +115 -93
- data/test/lint/lists.rb +86 -80
- data/test/lint/sets.rb +68 -62
- data/test/lint/sorted_sets.rb +200 -195
- data/test/lint/strings.rb +112 -94
- data/test/lint/value_types.rb +76 -55
- data/test/persistence_control_commands_test.rb +17 -12
- data/test/pipelining_commands_test.rb +135 -126
- data/test/publish_subscribe_test.rb +105 -110
- data/test/remote_server_control_commands_test.rb +74 -58
- data/test/sorting_test.rb +31 -29
- data/test/support/connection/hiredis.rb +1 -0
- data/test/support/connection/ruby.rb +1 -0
- data/test/support/connection/synchrony.rb +17 -0
- data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
- data/test/support/wire/synchrony.rb +24 -0
- data/test/support/wire/thread.rb +5 -0
- data/test/synchrony_driver.rb +9 -9
- data/test/test.conf +1 -1
- data/test/thread_safety_test.rb +21 -19
- data/test/transactions_test.rb +189 -118
- data/test/unknown_commands_test.rb +9 -8
- data/test/url_param_test.rb +46 -41
- metadata +28 -43
- data/TODO.md +0 -4
- data/benchmarking/thread_safety.rb +0 -38
- data/test/lint/internals.rb +0 -36
@@ -1,80 +1,89 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
3
|
+
require "helper"
|
4
|
+
require "lint/strings"
|
4
5
|
|
5
|
-
|
6
|
-
init Redis.new(OPTIONS)
|
7
|
-
end
|
6
|
+
class TestCommandsOnStrings < Test::Unit::TestCase
|
8
7
|
|
9
|
-
|
8
|
+
include Helper::Client
|
9
|
+
include Lint::Strings
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def test_mget
|
12
|
+
r.set("foo", "s1")
|
13
|
+
r.set("bar", "s2")
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
15
|
+
assert_equal ["s1", "s2"] , r.mget("foo", "bar")
|
16
|
+
assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def test_mget_mapped
|
20
|
+
r.set("foo", "s1")
|
21
|
+
r.set("bar", "s2")
|
22
22
|
|
23
|
-
|
23
|
+
response = r.mapped_mget("foo", "bar")
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
assert_equal "s1", response["foo"]
|
26
|
+
assert_equal "s2", response["bar"]
|
27
27
|
|
28
|
-
|
28
|
+
response = r.mapped_mget("foo", "bar", "baz")
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
30
|
+
assert_equal "s1", response["foo"]
|
31
|
+
assert_equal "s2", response["bar"]
|
32
|
+
assert_equal nil , response["baz"]
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def test_mapped_mget_in_a_pipeline_returns_hash
|
36
|
+
r.set("foo", "s1")
|
37
|
+
r.set("bar", "s2")
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
result = r.pipelined do
|
40
|
+
r.mapped_mget("foo", "bar")
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
end
|
43
|
+
assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
def test_mset
|
47
|
+
r.mset(:foo, "s1", :bar, "s2")
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
49
|
+
assert_equal "s1", r.get("foo")
|
50
|
+
assert_equal "s2", r.get("bar")
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
def test_mset_mapped
|
54
|
+
r.mapped_mset(:foo => "s1", :bar => "s2")
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
56
|
+
assert_equal "s1", r.get("foo")
|
57
|
+
assert_equal "s2", r.get("bar")
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
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")
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
|
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")
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
75
83
|
|
76
|
-
|
77
|
-
|
84
|
+
def test_strlen
|
85
|
+
r.set "foo", "lorem"
|
78
86
|
|
79
|
-
|
87
|
+
assert_equal 5, r.strlen("foo")
|
88
|
+
end
|
80
89
|
end
|
@@ -1,87 +1,99 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "helper"
|
4
|
+
require "lint/value_types"
|
5
5
|
|
6
|
-
|
6
|
+
class TestCommandsOnValueTypes < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
include Helper::Client
|
9
|
+
include Lint::ValueTypes
|
11
10
|
|
12
|
-
|
11
|
+
def test_del
|
12
|
+
r.set "foo", "s1"
|
13
|
+
r.set "bar", "s2"
|
14
|
+
r.set "baz", "s3"
|
13
15
|
|
14
|
-
|
15
|
-
r.set "foo", "s1"
|
16
|
-
r.set "bar", "s2"
|
17
|
-
r.set "baz", "s3"
|
16
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
18
17
|
|
19
|
-
|
18
|
+
assert_equal 1, r.del("foo")
|
20
19
|
|
21
|
-
|
20
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
22
21
|
|
23
|
-
|
22
|
+
assert_equal 2, r.del("bar", "baz")
|
24
23
|
|
25
|
-
|
24
|
+
assert_equal [], r.keys("*").sort
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
def test_del_with_array_argument
|
28
|
+
r.set "foo", "s1"
|
29
|
+
r.set "bar", "s2"
|
30
|
+
r.set "baz", "s3"
|
29
31
|
|
30
|
-
|
31
|
-
assert r.randomkey.to_s.empty?
|
32
|
+
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
32
33
|
|
33
|
-
|
34
|
+
assert_equal 1, r.del(["foo"])
|
34
35
|
|
35
|
-
|
36
|
+
assert_equal ["bar", "baz"], r.keys("*").sort
|
36
37
|
|
37
|
-
|
38
|
+
assert_equal 2, r.del(["bar", "baz"])
|
38
39
|
|
39
|
-
|
40
|
-
assert ["foo", "bar"].include?(r.randomkey)
|
40
|
+
assert_equal [], r.keys("*").sort
|
41
41
|
end
|
42
|
-
end
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
r.rename "foo", "bar"
|
43
|
+
def test_randomkey
|
44
|
+
assert r.randomkey.to_s.empty?
|
47
45
|
|
48
|
-
|
49
|
-
assert nil == r.get("foo")
|
50
|
-
end
|
46
|
+
r.set("foo", "s1")
|
51
47
|
|
52
|
-
|
53
|
-
r.set("foo", "s1")
|
54
|
-
r.set("bar", "s2")
|
48
|
+
assert_equal "foo", r.randomkey
|
55
49
|
|
56
|
-
|
50
|
+
r.set("bar", "s2")
|
57
51
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
52
|
+
4.times do
|
53
|
+
assert ["foo", "bar"].include?(r.randomkey)
|
54
|
+
end
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
57
|
+
def test_rename
|
58
|
+
r.set("foo", "s1")
|
59
|
+
r.rename "foo", "bar"
|
64
60
|
|
65
|
-
|
61
|
+
assert_equal "s1", r.get("bar")
|
62
|
+
assert_equal nil, r.get("foo")
|
63
|
+
end
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
def test_renamenx
|
66
|
+
r.set("foo", "s1")
|
67
|
+
r.set("bar", "s2")
|
69
68
|
|
70
|
-
|
71
|
-
r.set("foo", "s1")
|
72
|
-
r.set("bar", "s2")
|
69
|
+
assert_equal false, r.renamenx("foo", "bar")
|
73
70
|
|
74
|
-
|
71
|
+
assert_equal "s1", r.get("foo")
|
72
|
+
assert_equal "s2", r.get("bar")
|
73
|
+
end
|
75
74
|
|
76
|
-
|
75
|
+
def test_dbsize
|
76
|
+
assert_equal 0, r.dbsize
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
r.set("foo", "s1")
|
79
|
+
|
80
|
+
assert_equal 1, r.dbsize
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
84
93
|
|
85
|
-
|
94
|
+
def test_flushall
|
95
|
+
redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
|
96
|
+
assert_equal "FLUSHALL", redis.flushall
|
97
|
+
end
|
86
98
|
end
|
87
99
|
end
|
@@ -1,204 +1,189 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require File.expand_path("./redis_mock", File.dirname(__FILE__))
|
3
|
+
require "helper"
|
5
4
|
|
6
|
-
|
5
|
+
class TestConnectionHandling < Test::Unit::TestCase
|
7
6
|
|
8
|
-
|
9
|
-
init Redis.new(OPTIONS)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "AUTH" do
|
13
|
-
replies = {
|
14
|
-
:auth => lambda { |password| $auth = password; "+OK" },
|
15
|
-
:get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
|
16
|
-
}
|
7
|
+
include Helper::Client
|
17
8
|
|
18
|
-
|
19
|
-
|
9
|
+
def test_auth
|
10
|
+
commands = {
|
11
|
+
:auth => lambda { |password| $auth = password; "+OK" },
|
12
|
+
:get => lambda { |key| $auth == "secret" ? "$3\r\nbar" : "$-1" },
|
13
|
+
}
|
20
14
|
|
21
|
-
|
15
|
+
redis_mock(commands, :password => "secret") do |redis|
|
16
|
+
assert_equal "bar", redis.get("foo")
|
17
|
+
end
|
22
18
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
test "PING" do |r|
|
26
|
-
assert "PONG" == r.ping
|
27
|
-
end
|
28
19
|
|
29
|
-
|
30
|
-
|
20
|
+
def test_ping
|
21
|
+
assert_equal "PONG", r.ping
|
22
|
+
end
|
31
23
|
|
32
|
-
|
33
|
-
|
24
|
+
def test_select
|
25
|
+
r.set "foo", "bar"
|
34
26
|
|
35
|
-
|
27
|
+
r.select 14
|
28
|
+
assert_equal nil, r.get("foo")
|
36
29
|
|
37
|
-
|
38
|
-
end
|
30
|
+
r.client.disconnect
|
39
31
|
|
40
|
-
|
41
|
-
|
32
|
+
assert_equal nil, r.get("foo")
|
33
|
+
end
|
42
34
|
|
43
|
-
|
44
|
-
|
35
|
+
def test_quit
|
36
|
+
r.quit
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
:shutdown => lambda { :exit }
|
49
|
-
}
|
38
|
+
assert !r.client.connected?
|
39
|
+
end
|
50
40
|
|
51
|
-
|
52
|
-
|
41
|
+
def test_shutdown
|
42
|
+
commands = {
|
43
|
+
:shutdown => lambda { :exit }
|
44
|
+
}
|
53
45
|
|
54
|
-
|
55
|
-
|
46
|
+
redis_mock(commands) do |redis|
|
47
|
+
# SHUTDOWN does not reply: test that it does not raise here.
|
48
|
+
assert_equal nil, redis.shutdown
|
49
|
+
end
|
56
50
|
end
|
57
|
-
end
|
58
51
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
def test_shutdown_with_error
|
53
|
+
connections = 0
|
54
|
+
commands = {
|
55
|
+
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
56
|
+
:connections => lambda { ":#{connections}\r\n" },
|
57
|
+
:shutdown => lambda { "-ERR could not shutdown\r\n" }
|
58
|
+
}
|
66
59
|
|
67
|
-
|
68
|
-
|
60
|
+
redis_mock(commands) do |redis|
|
61
|
+
connections = redis.connections
|
69
62
|
|
70
|
-
|
63
|
+
# SHUTDOWN replies with an error: test that it gets raised
|
64
|
+
assert_raise Redis::CommandError do
|
65
|
+
redis.shutdown
|
66
|
+
end
|
71
67
|
|
72
|
-
|
73
|
-
|
74
|
-
redis.shutdown
|
68
|
+
# The connection should remain in tact
|
69
|
+
assert_equal connections, redis.connections
|
75
70
|
end
|
76
|
-
|
77
|
-
# The connection should remain in tact
|
78
|
-
assert connections == redis.connections
|
79
71
|
end
|
80
|
-
end
|
81
72
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
def test_shutdown_from_pipeline
|
74
|
+
commands = {
|
75
|
+
:shutdown => lambda { :exit }
|
76
|
+
}
|
86
77
|
|
87
|
-
|
88
|
-
|
78
|
+
redis_mock(commands) do |redis|
|
79
|
+
result = redis.pipelined do
|
80
|
+
redis.shutdown
|
81
|
+
end
|
89
82
|
|
90
|
-
|
91
|
-
redis.
|
83
|
+
assert_equal nil, result
|
84
|
+
assert !redis.client.connected?
|
92
85
|
end
|
93
|
-
|
94
|
-
assert nil == result
|
95
|
-
assert !redis.client.connected?
|
96
86
|
end
|
97
|
-
end
|
98
87
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
88
|
+
def test_shutdown_with_error_from_pipeline
|
89
|
+
connections = 0
|
90
|
+
commands = {
|
91
|
+
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
92
|
+
:connections => lambda { ":#{connections}\r\n" },
|
93
|
+
:shutdown => lambda { "-ERR could not shutdown\r\n" }
|
94
|
+
}
|
95
|
+
|
96
|
+
redis_mock(commands) do |redis|
|
97
|
+
connections = redis.connections
|
98
|
+
|
99
|
+
# SHUTDOWN replies with an error: test that it gets raised
|
100
|
+
assert_raise Redis::CommandError do
|
101
|
+
redis.pipelined do
|
102
|
+
redis.shutdown
|
103
|
+
end
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
106
|
+
# The connection should remain in tact
|
107
|
+
assert_equal connections, redis.connections
|
108
|
+
end
|
109
|
+
end
|
109
110
|
|
110
|
-
|
111
|
+
def test_shutdown_from_multi_exec
|
112
|
+
commands = {
|
113
|
+
:multi => lambda { "+OK\r\n" },
|
114
|
+
:shutdown => lambda { "+QUEUED\r\n" },
|
115
|
+
:exec => lambda { :exit }
|
116
|
+
}
|
111
117
|
|
112
|
-
|
113
|
-
|
114
|
-
redis.pipelined do
|
118
|
+
redis_mock(commands) do |redis|
|
119
|
+
result = redis.multi do
|
115
120
|
redis.shutdown
|
116
121
|
end
|
117
|
-
end
|
118
122
|
|
119
|
-
|
120
|
-
|
123
|
+
assert_equal nil, result
|
124
|
+
assert !redis.client.connected?
|
125
|
+
end
|
121
126
|
end
|
122
|
-
end
|
123
127
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
def test_shutdown_with_error_from_multi_exec
|
129
|
+
connections = 0
|
130
|
+
commands = {
|
131
|
+
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
132
|
+
:connections => lambda { ":#{connections}\r\n" },
|
133
|
+
:multi => lambda { "+OK\r\n" },
|
134
|
+
:shutdown => lambda { "+QUEUED\r\n" },
|
135
|
+
:exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
|
136
|
+
}
|
137
|
+
|
138
|
+
redis_mock(commands) do |redis|
|
139
|
+
connections = redis.connections
|
140
|
+
|
141
|
+
# SHUTDOWN replies with an error: test that it gets returned
|
142
|
+
# We should test for Redis::CommandError here, but hiredis doesn't yet do
|
143
|
+
# custom error classes.
|
144
|
+
err = nil
|
145
|
+
|
146
|
+
begin
|
147
|
+
redis.multi { redis.shutdown }
|
148
|
+
rescue => err
|
149
|
+
end
|
130
150
|
|
131
|
-
|
132
|
-
redis = Redis.new(OPTIONS.merge(:port => 6380))
|
151
|
+
assert err.kind_of?(StandardError)
|
133
152
|
|
134
|
-
|
135
|
-
redis.
|
153
|
+
# The connection should remain intact
|
154
|
+
assert_equal connections, redis.connections
|
136
155
|
end
|
137
|
-
|
138
|
-
assert nil == result
|
139
|
-
assert !redis.client.connected?
|
140
156
|
end
|
141
|
-
end
|
142
157
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
:select => lambda { |*_| connections += 1; "+OK\r\n" },
|
147
|
-
:connections => lambda { ":#{connections}\r\n" },
|
148
|
-
:multi => lambda { "+OK\r\n" },
|
149
|
-
:shutdown => lambda { "+QUEUED\r\n" },
|
150
|
-
:exec => lambda { "*1\r\n-ERR could not shutdown\r\n" }
|
151
|
-
}
|
152
|
-
|
153
|
-
redis_mock(commands) do
|
154
|
-
redis = Redis.new(OPTIONS.merge(:port => 6380))
|
155
|
-
|
156
|
-
connections = redis.connections
|
157
|
-
|
158
|
-
# SHUTDOWN replies with an error: test that it gets returned
|
159
|
-
# We should test for Redis::CommandError here, but hiredis doesn't yet do
|
160
|
-
# custom error classes.
|
161
|
-
assert_raise(StandardError) do
|
162
|
-
redis.multi { redis.shutdown }
|
158
|
+
def test_slaveof
|
159
|
+
redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do |redis|
|
160
|
+
assert_equal "SLAVEOF localhost 6381", redis.slaveof("localhost", 6381)
|
163
161
|
end
|
164
|
-
|
165
|
-
# The connection should remain intact
|
166
|
-
assert connections == redis.connections
|
167
162
|
end
|
168
|
-
end
|
169
|
-
|
170
|
-
test "SLAVEOF" do
|
171
|
-
redis_mock(:slaveof => lambda { |host, port| "+SLAVEOF #{host} #{port}" }) do
|
172
|
-
redis = Redis.new(OPTIONS.merge(:port => 6380))
|
173
163
|
|
174
|
-
|
164
|
+
def test_bgrewriteaof
|
165
|
+
redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do |redis|
|
166
|
+
assert_equal "BGREWRITEAOF", redis.bgrewriteaof
|
167
|
+
end
|
175
168
|
end
|
176
|
-
end
|
177
169
|
|
178
|
-
|
179
|
-
|
180
|
-
redis = Redis.new(OPTIONS.merge(:port => 6380))
|
170
|
+
def test_config_get
|
171
|
+
assert r.config(:get, "*")["timeout"] != nil
|
181
172
|
|
182
|
-
|
173
|
+
config = r.config(:get, "timeout")
|
174
|
+
assert_equal ["timeout"], config.keys
|
175
|
+
assert config.values.compact.size > 0
|
183
176
|
end
|
184
|
-
end
|
185
|
-
|
186
|
-
test "CONFIG GET" do |r|
|
187
|
-
assert r.config(:get, "*")["timeout"] != nil
|
188
177
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
def test_config_set
|
179
|
+
begin
|
180
|
+
assert_equal "OK", r.config(:set, "timeout", 200)
|
181
|
+
assert_equal "200", r.config(:get, "*")["timeout"]
|
193
182
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
assert "OK" == r.config(:set, "timeout", 100)
|
200
|
-
assert "100" == r.config(:get, "*")["timeout"]
|
201
|
-
ensure
|
202
|
-
r.config :set, "timeout", 300
|
183
|
+
assert_equal "OK", r.config(:set, "timeout", 100)
|
184
|
+
assert_equal "100", r.config(:get, "*")["timeout"]
|
185
|
+
ensure
|
186
|
+
r.config :set, "timeout", 300
|
187
|
+
end
|
203
188
|
end
|
204
189
|
end
|