Skip to content

Commit 179a6c4

Browse files
committed
Merge pull request #506 from redis/disconnect
Add `Redis#disconnect!` as a public-API way of disconnecting.
2 parents 964ccf7 + 0361bba commit 179a6c4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/redis.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def connected?
5454
@original_client.connected?
5555
end
5656

57+
# Disconnect the client as quickly and silently as possible.
58+
def disconnect!
59+
@original_client.disconnect
60+
end
61+
5762
# Authenticate to the server.
5863
#
5964
# @param [String] password must match the password specified in the

test/connection_handling_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ def test_quit
3838
assert !r.client.connected?
3939
end
4040

41+
def test_disconnect
42+
quit = 0
43+
44+
commands = {
45+
:quit => lambda do
46+
quit += 1
47+
"+OK"
48+
end
49+
}
50+
51+
redis_mock(commands) do |redis|
52+
assert_equal 0, quit
53+
54+
redis.quit
55+
56+
assert_equal 1, quit
57+
58+
redis.ping
59+
60+
redis.disconnect!
61+
62+
assert_equal 1, quit
63+
64+
assert !redis.connected?
65+
end
66+
end
67+
4168
def test_shutdown
4269
commands = {
4370
:shutdown => lambda { :exit }

0 commit comments

Comments
 (0)