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.
Files changed (77) hide show
  1. data/.travis.yml +50 -0
  2. data/.travis/Gemfile +11 -0
  3. data/CHANGELOG.md +47 -19
  4. data/README.md +160 -149
  5. data/Rakefile +15 -50
  6. data/examples/pubsub.rb +1 -1
  7. data/examples/unicorn/config.ru +1 -1
  8. data/examples/unicorn/unicorn.rb +1 -1
  9. data/lib/redis.rb +790 -390
  10. data/lib/redis/client.rb +137 -49
  11. data/lib/redis/connection/hiredis.rb +26 -15
  12. data/lib/redis/connection/ruby.rb +170 -53
  13. data/lib/redis/connection/synchrony.rb +23 -35
  14. data/lib/redis/distributed.rb +92 -32
  15. data/lib/redis/errors.rb +4 -2
  16. data/lib/redis/pipeline.rb +17 -6
  17. data/lib/redis/version.rb +1 -1
  18. data/redis.gemspec +4 -6
  19. data/test/blocking_commands_test.rb +42 -0
  20. data/test/command_map_test.rb +18 -17
  21. data/test/commands_on_hashes_test.rb +13 -12
  22. data/test/commands_on_lists_test.rb +35 -45
  23. data/test/commands_on_sets_test.rb +55 -54
  24. data/test/commands_on_sorted_sets_test.rb +106 -105
  25. data/test/commands_on_strings_test.rb +64 -55
  26. data/test/commands_on_value_types_test.rb +66 -54
  27. data/test/connection_handling_test.rb +136 -151
  28. data/test/distributed_blocking_commands_test.rb +33 -40
  29. data/test/distributed_commands_on_hashes_test.rb +6 -7
  30. data/test/distributed_commands_on_lists_test.rb +13 -14
  31. data/test/distributed_commands_on_sets_test.rb +57 -58
  32. data/test/distributed_commands_on_sorted_sets_test.rb +11 -12
  33. data/test/distributed_commands_on_strings_test.rb +31 -32
  34. data/test/distributed_commands_on_value_types_test.rb +61 -46
  35. data/test/distributed_commands_requiring_clustering_test.rb +108 -108
  36. data/test/distributed_connection_handling_test.rb +14 -15
  37. data/test/distributed_internals_test.rb +7 -19
  38. data/test/distributed_key_tags_test.rb +36 -36
  39. data/test/distributed_persistence_control_commands_test.rb +17 -14
  40. data/test/distributed_publish_subscribe_test.rb +61 -69
  41. data/test/distributed_remote_server_control_commands_test.rb +39 -28
  42. data/test/distributed_sorting_test.rb +12 -13
  43. data/test/distributed_test.rb +40 -41
  44. data/test/distributed_transactions_test.rb +20 -21
  45. data/test/encoding_test.rb +12 -9
  46. data/test/error_replies_test.rb +42 -36
  47. data/test/helper.rb +118 -85
  48. data/test/helper_test.rb +20 -6
  49. data/test/internals_test.rb +167 -103
  50. data/test/lint/blocking_commands.rb +124 -0
  51. data/test/lint/hashes.rb +115 -93
  52. data/test/lint/lists.rb +86 -80
  53. data/test/lint/sets.rb +68 -62
  54. data/test/lint/sorted_sets.rb +200 -195
  55. data/test/lint/strings.rb +112 -94
  56. data/test/lint/value_types.rb +76 -55
  57. data/test/persistence_control_commands_test.rb +17 -12
  58. data/test/pipelining_commands_test.rb +135 -126
  59. data/test/publish_subscribe_test.rb +105 -110
  60. data/test/remote_server_control_commands_test.rb +74 -58
  61. data/test/sorting_test.rb +31 -29
  62. data/test/support/connection/hiredis.rb +1 -0
  63. data/test/support/connection/ruby.rb +1 -0
  64. data/test/support/connection/synchrony.rb +17 -0
  65. data/test/{redis_mock.rb → support/redis_mock.rb} +24 -21
  66. data/test/support/wire/synchrony.rb +24 -0
  67. data/test/support/wire/thread.rb +5 -0
  68. data/test/synchrony_driver.rb +9 -9
  69. data/test/test.conf +1 -1
  70. data/test/thread_safety_test.rb +21 -19
  71. data/test/transactions_test.rb +189 -118
  72. data/test/unknown_commands_test.rb +9 -8
  73. data/test/url_param_test.rb +46 -41
  74. metadata +28 -43
  75. data/TODO.md +0 -4
  76. data/benchmarking/thread_safety.rb +0 -38
  77. data/test/lint/internals.rb +0 -36
@@ -1,80 +1,89 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require File.expand_path("./helper", File.dirname(__FILE__))
3
+ require "helper"
4
+ require "lint/strings"
4
5
 
5
- setup do
6
- init Redis.new(OPTIONS)
7
- end
6
+ class TestCommandsOnStrings < Test::Unit::TestCase
8
7
 
9
- load './test/lint/strings.rb'
8
+ include Helper::Client
9
+ include Lint::Strings
10
10
 
11
- test "MGET" do |r|
12
- r.set("foo", "s1")
13
- r.set("bar", "s2")
11
+ def test_mget
12
+ r.set("foo", "s1")
13
+ r.set("bar", "s2")
14
14
 
15
- assert ["s1", "s2"] == r.mget("foo", "bar")
16
- assert ["s1", "s2", nil] == r.mget("foo", "bar", "baz")
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
- test "MGET mapped" do |r|
20
- r.set("foo", "s1")
21
- r.set("bar", "s2")
19
+ def test_mget_mapped
20
+ r.set("foo", "s1")
21
+ r.set("bar", "s2")
22
22
 
23
- response = r.mapped_mget("foo", "bar")
23
+ response = r.mapped_mget("foo", "bar")
24
24
 
25
- assert "s1" == response["foo"]
26
- assert "s2" == response["bar"]
25
+ assert_equal "s1", response["foo"]
26
+ assert_equal "s2", response["bar"]
27
27
 
28
- response = r.mapped_mget("foo", "bar", "baz")
28
+ response = r.mapped_mget("foo", "bar", "baz")
29
29
 
30
- assert "s1" == response["foo"]
31
- assert "s2" == response["bar"]
32
- assert nil == response["baz"]
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
- test "Mapped MGET in a pipeline returns hash" do |r|
36
- r.set("foo", "s1")
37
- r.set("bar", "s2")
35
+ def test_mapped_mget_in_a_pipeline_returns_hash
36
+ r.set("foo", "s1")
37
+ r.set("bar", "s2")
38
38
 
39
- result = r.pipelined do
40
- r.mapped_mget("foo", "bar")
41
- end
39
+ result = r.pipelined do
40
+ r.mapped_mget("foo", "bar")
41
+ end
42
42
 
43
- assert result[0] == { "foo" => "s1", "bar" => "s2" }
44
- end
43
+ assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
44
+ end
45
45
 
46
- test "MSET" do |r|
47
- r.mset(:foo, "s1", :bar, "s2")
46
+ def test_mset
47
+ r.mset(:foo, "s1", :bar, "s2")
48
48
 
49
- assert "s1" == r.get("foo")
50
- assert "s2" == r.get("bar")
51
- end
49
+ assert_equal "s1", r.get("foo")
50
+ assert_equal "s2", r.get("bar")
51
+ end
52
52
 
53
- test "MSET mapped" do |r|
54
- r.mapped_mset(:foo => "s1", :bar => "s2")
53
+ def test_mset_mapped
54
+ r.mapped_mset(:foo => "s1", :bar => "s2")
55
55
 
56
- assert "s1" == r.get("foo")
57
- assert "s2" == r.get("bar")
58
- end
56
+ assert_equal "s1", r.get("foo")
57
+ assert_equal "s2", r.get("bar")
58
+ end
59
59
 
60
- test "MSETNX" do |r|
61
- r.set("foo", "s1")
62
- r.msetnx(:foo, "s2", :bar, "s3")
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
- assert "s1" == r.get("foo")
65
- assert nil == r.get("bar")
66
- end
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
- test "MSETNX mapped" do |r|
69
- r.set("foo", "s1")
70
- r.mapped_msetnx(:foo => "s2", :bar => "s3")
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
- assert "s1" == r.get("foo")
73
- assert nil == r.get("bar")
74
- end
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
- test "STRLEN" do |r|
77
- r.set "foo", "lorem"
84
+ def test_strlen
85
+ r.set "foo", "lorem"
78
86
 
79
- assert 5 == r.strlen("foo")
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require File.expand_path("./redis_mock", File.dirname(__FILE__))
3
+ require "helper"
4
+ require "lint/value_types"
5
5
 
6
- include RedisMock::Helper
6
+ class TestCommandsOnValueTypes < Test::Unit::TestCase
7
7
 
8
- setup do
9
- init Redis.new(OPTIONS)
10
- end
8
+ include Helper::Client
9
+ include Lint::ValueTypes
11
10
 
12
- load "./test/lint/value_types.rb"
11
+ def test_del
12
+ r.set "foo", "s1"
13
+ r.set "bar", "s2"
14
+ r.set "baz", "s3"
13
15
 
14
- test "DEL" do |r|
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
- assert ["bar", "baz", "foo"] == r.keys("*").sort
18
+ assert_equal 1, r.del("foo")
20
19
 
21
- assert 1 == r.del("foo")
20
+ assert_equal ["bar", "baz"], r.keys("*").sort
22
21
 
23
- assert ["bar", "baz"] == r.keys("*").sort
22
+ assert_equal 2, r.del("bar", "baz")
24
23
 
25
- assert 2 == r.del("bar", "baz")
24
+ assert_equal [], r.keys("*").sort
25
+ end
26
26
 
27
- assert [] == r.keys("*").sort
28
- end
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
- test "RANDOMKEY" do |r|
31
- assert r.randomkey.to_s.empty?
32
+ assert_equal ["bar", "baz", "foo"], r.keys("*").sort
32
33
 
33
- r.set("foo", "s1")
34
+ assert_equal 1, r.del(["foo"])
34
35
 
35
- assert "foo" == r.randomkey
36
+ assert_equal ["bar", "baz"], r.keys("*").sort
36
37
 
37
- r.set("bar", "s2")
38
+ assert_equal 2, r.del(["bar", "baz"])
38
39
 
39
- 4.times do
40
- assert ["foo", "bar"].include?(r.randomkey)
40
+ assert_equal [], r.keys("*").sort
41
41
  end
42
- end
43
42
 
44
- test "RENAME" do |r|
45
- r.set("foo", "s1")
46
- r.rename "foo", "bar"
43
+ def test_randomkey
44
+ assert r.randomkey.to_s.empty?
47
45
 
48
- assert "s1" == r.get("bar")
49
- assert nil == r.get("foo")
50
- end
46
+ r.set("foo", "s1")
51
47
 
52
- test "RENAMENX" do |r|
53
- r.set("foo", "s1")
54
- r.set("bar", "s2")
48
+ assert_equal "foo", r.randomkey
55
49
 
56
- assert false == r.renamenx("foo", "bar")
50
+ r.set("bar", "s2")
57
51
 
58
- assert "s1" == r.get("foo")
59
- assert "s2" == r.get("bar")
60
- end
52
+ 4.times do
53
+ assert ["foo", "bar"].include?(r.randomkey)
54
+ end
55
+ end
61
56
 
62
- test "DBSIZE" do |r|
63
- assert 0 == r.dbsize
57
+ def test_rename
58
+ r.set("foo", "s1")
59
+ r.rename "foo", "bar"
64
60
 
65
- r.set("foo", "s1")
61
+ assert_equal "s1", r.get("bar")
62
+ assert_equal nil, r.get("foo")
63
+ end
66
64
 
67
- assert 1 == r.dbsize
68
- end
65
+ def test_renamenx
66
+ r.set("foo", "s1")
67
+ r.set("bar", "s2")
69
68
 
70
- test "FLUSHDB" do |r|
71
- r.set("foo", "s1")
72
- r.set("bar", "s2")
69
+ assert_equal false, r.renamenx("foo", "bar")
73
70
 
74
- assert 2 == r.dbsize
71
+ assert_equal "s1", r.get("foo")
72
+ assert_equal "s2", r.get("bar")
73
+ end
75
74
 
76
- r.flushdb
75
+ def test_dbsize
76
+ assert_equal 0, r.dbsize
77
77
 
78
- assert 0 == r.dbsize
79
- end
78
+ r.set("foo", "s1")
79
+
80
+ assert_equal 1, r.dbsize
81
+ end
80
82
 
81
- test "FLUSHALL" do
82
- redis_mock(:flushall => lambda { "+FLUSHALL" }) do
83
- redis = Redis.new(OPTIONS.merge(:port => 6380))
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
- assert "FLUSHALL" == redis.flushall
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 File.expand_path("./helper", File.dirname(__FILE__))
4
- require File.expand_path("./redis_mock", File.dirname(__FILE__))
3
+ require "helper"
5
4
 
6
- include RedisMock::Helper
5
+ class TestConnectionHandling < Test::Unit::TestCase
7
6
 
8
- setup do
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
- redis_mock(replies) do
19
- redis = Redis.new(OPTIONS.merge(:port => 6380, :password => "secret"))
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
- assert "bar" == redis.get("foo")
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
- test "SELECT" do |r|
30
- r.set "foo", "bar"
20
+ def test_ping
21
+ assert_equal "PONG", r.ping
22
+ end
31
23
 
32
- r.select 14
33
- assert nil == r.get("foo")
24
+ def test_select
25
+ r.set "foo", "bar"
34
26
 
35
- r.client.disconnect
27
+ r.select 14
28
+ assert_equal nil, r.get("foo")
36
29
 
37
- assert nil == r.get("foo")
38
- end
30
+ r.client.disconnect
39
31
 
40
- test "QUIT" do |r|
41
- r.quit
32
+ assert_equal nil, r.get("foo")
33
+ end
42
34
 
43
- assert !r.client.connected?
44
- end
35
+ def test_quit
36
+ r.quit
45
37
 
46
- test "SHUTDOWN" do
47
- commands = {
48
- :shutdown => lambda { :exit }
49
- }
38
+ assert !r.client.connected?
39
+ end
50
40
 
51
- redis_mock(commands) do
52
- redis = Redis.new(OPTIONS.merge(:port => 6380))
41
+ def test_shutdown
42
+ commands = {
43
+ :shutdown => lambda { :exit }
44
+ }
53
45
 
54
- # SHUTDOWN does not reply: test that it does not raise here.
55
- assert nil == redis.shutdown
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
- test "SHUTDOWN with error" do
60
- connections = 0
61
- commands = {
62
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
63
- :connections => lambda { ":#{connections}\r\n" },
64
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
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
- redis_mock(commands) do
68
- redis = Redis.new(OPTIONS.merge(:port => 6380))
60
+ redis_mock(commands) do |redis|
61
+ connections = redis.connections
69
62
 
70
- connections = redis.connections
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
- # SHUTDOWN replies with an error: test that it gets raised
73
- assert_raise Redis::CommandError do
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
- test "SHUTDOWN from pipeline" do
83
- commands = {
84
- :shutdown => lambda { :exit }
85
- }
73
+ def test_shutdown_from_pipeline
74
+ commands = {
75
+ :shutdown => lambda { :exit }
76
+ }
86
77
 
87
- redis_mock(commands) do
88
- redis = Redis.new(OPTIONS.merge(:port => 6380))
78
+ redis_mock(commands) do |redis|
79
+ result = redis.pipelined do
80
+ redis.shutdown
81
+ end
89
82
 
90
- result = redis.pipelined do
91
- redis.shutdown
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
- test "SHUTDOWN with error from pipeline" do
100
- connections = 0
101
- commands = {
102
- :select => lambda { |*_| connections += 1; "+OK\r\n" },
103
- :connections => lambda { ":#{connections}\r\n" },
104
- :shutdown => lambda { "-ERR could not shutdown\r\n" }
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
- redis_mock(commands) do
108
- redis = Redis.new(OPTIONS.merge(:port => 6380))
106
+ # The connection should remain in tact
107
+ assert_equal connections, redis.connections
108
+ end
109
+ end
109
110
 
110
- connections = redis.connections
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
- # SHUTDOWN replies with an error: test that it gets raised
113
- assert_raise Redis::CommandError do
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
- # The connection should remain in tact
120
- assert connections == redis.connections
123
+ assert_equal nil, result
124
+ assert !redis.client.connected?
125
+ end
121
126
  end
122
- end
123
127
 
124
- test "SHUTDOWN from MULTI/EXEC" do
125
- commands = {
126
- :multi => lambda { "+OK\r\n" },
127
- :shutdown => lambda { "+QUEUED\r\n" },
128
- :exec => lambda { :exit }
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
- redis_mock(commands) do
132
- redis = Redis.new(OPTIONS.merge(:port => 6380))
151
+ assert err.kind_of?(StandardError)
133
152
 
134
- result = redis.multi do
135
- redis.shutdown
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
- test "SHUTDOWN with error from MULTI/EXEC" do
144
- connections = 0
145
- commands = {
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
- assert "SLAVEOF localhost 6381" == redis.slaveof("localhost", 6381)
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
- test "BGREWRITEAOF" do
179
- redis_mock(:bgrewriteaof => lambda { "+BGREWRITEAOF" }) do
180
- redis = Redis.new(OPTIONS.merge(:port => 6380))
170
+ def test_config_get
171
+ assert r.config(:get, "*")["timeout"] != nil
181
172
 
182
- assert "BGREWRITEAOF" == redis.bgrewriteaof
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
- config = r.config(:get, "timeout")
190
- assert ["timeout"] == config.keys
191
- assert config.values.compact.size > 0
192
- end
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
- test "CONFIG SET" do |r|
195
- begin
196
- assert "OK" == r.config(:set, "timeout", 200)
197
- assert "200" == r.config(:get, "*")["timeout"]
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