Move QUIT command out of the common case
authorPedro Melo <melo@simplicidade.org>
Wed, 4 Aug 2010 20:31:01 +0000 (21:31 +0100)
committerPedro Melo <melo@simplicidade.org>
Wed, 4 Aug 2010 20:31:01 +0000 (21:31 +0100)
Make sure we get rid of the IO::Socket::INET object on QUIT.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
lib/Redis.pm

index a764584..ca065b9 100644 (file)
@@ -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 {