From 529539c1e3bc1aa0a19bb9bde72a2352be7f76ff Mon Sep 17 00:00:00 2001 From: Pedro Melo Date: Wed, 4 Aug 2010 21:31:01 +0100 Subject: [PATCH] Move QUIT command out of the common case Make sure we get rid of the IO::Socket::INET object on QUIT. Signed-off-by: Pedro Melo --- lib/Redis.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/Redis.pm b/lib/Redis.pm index a764584..ca065b9 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -60,6 +60,8 @@ sub new { # we don't want DESTROY to fallback into AUTOLOAD sub DESTROY {} + +### Deal with common, general case, Redis commands our $AUTOLOAD; sub AUTOLOAD { my $self = shift; @@ -72,11 +74,6 @@ sub AUTOLOAD { $self->__send_command($command, @_); - if ( $command eq 'quit' ) { - close( $sock ) || confess("Can't close socket: $!"); - return 1; - } - my $result = <$sock> || confess("Can't read socket: $!"); my $type = substr($result,0,1); $result = substr($result,1,-2); @@ -115,6 +112,18 @@ sub AUTOLOAD { } +### Commands with extra logic + +sub quit { + my ($self) = @_; + + $self->__send_command('QUIT'); + + close(delete $self->{sock}) || confess("Can't close socket: $!"); + return 1; +} + + ### Socket operations sub __send_command { -- 2.20.1