reconnect to redis if the connection went away
[perl-Redis.git] / lib / Redis.pm
index 82aeae0..e267ec4 100644 (file)
@@ -117,7 +117,17 @@ sub AUTOLOAD {
                return 1;
        }
 
-       my $result = <$sock> || die "can't read socket: $!";
+       my $result = <$sock>;
+       if ( !$result ) {
+               $self->{sock} = $sock = IO::Socket::INET->new(
+                       PeerAddr => $self->{server},
+                       Proto => 'tcp',
+               ) || die $!;
+
+               print $sock $send;
+
+               $result = <$sock> || die "can't read socket: $!";
+       }
        Encode::_utf8_on($result);
        warn "<< $result" if $self->{debug};
        my $type = substr($result,0,1);
@@ -372,6 +382,14 @@ See also L<Redis::List> for tie interface.
 
   my $info_hash = $r->info;
 
+=head1 ENCODING
+
+Since Redis knows nothing about encoding, we are forcing utf-8 flag on all data received from Redis.
+This change is introduced in 1.2001 version.
+
+This allows us to round-trip utf-8 encoded characters correctly, but might be problem if you push
+binary junk into Redis and expect to get it back without utf-8 flag turned on.
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>