p5-RedisDB / RedisDB

Perl extension to access Redis
22 stars 11 forks source link

Next request fails after reconnect #16

Closed sergunSpb closed 10 years ago

sergunSpb commented 10 years ago

Hello, Pavel. If redis server falls between requests , we'll get exception:

Couldn't connect to the redis server at localhost:6379: В соединении отказано at /usr/local/lib/perl/5.14.2/RedisDB.pm line 198.
    RedisDB::_on_connect_error('RedisDB=HASH(0x2348998)', '\x{d0}\x{92} \x{d1}\x{81}\x{d0}\x{be}\x{d0}\x{b5}\x{d0}\x{b4}\x{d0}\x{b8}\x{d0}\x{bd}\x{d0}\x{b5}\x{d0}\x{bd}\x{d0}\x{b8}\x{d0}\x{b8} \x{d0}\x{be}\x{d1}\x{82}\x{d0}\x{ba}\x{d0}\x{b0}\x{d0}\x{b7}\x{d0}\x{b0}\x{d0}\x{bd}\x{d0}\x{be}') called at /usr/local/lib/perl/5.14.2/RedisDB.pm line 257
    RedisDB::_connect('RedisDB=HASH(0x2348998)') called at /usr/local/lib/perl/5.14.2/RedisDB.pm line 394
    RedisDB::_recv_data_nb('RedisDB=HASH(0x2348998)') called at /usr/local/lib/perl/5.14.2/RedisDB.pm line 473
    RedisDB::send_command('RedisDB=HASH(0x2348998)', 'KEYS', '*') called at /usr/local/lib/perl/5.14.2/RedisDB.pm line 191
    RedisDB::execute('RedisDB=HASH(0x2348998)', 'keys', '*') called at t.pl line 14

When redis server is resurrected , next request will fail with error :

You can't use RedisDB::execute when you have replies to fetch. at t.pl line 13.

Why next request fails ? Is it bug ? And how can i flush replies to fetch ?

It's example of code:

use strict;
use warnings;
use utf8;
use RedisDB;
my $redis = RedisDB->new(( host => 'localhost'  , reconnect_attemps => 0));
for( my $i = 0 ; $i < 3 ; $i++ ){
    eval{
        $redis->execute("keys" , "*");
    };
    print $@;
    print $i."\n";
    sleep 5;
}
trinitum commented 10 years ago

Thanks for the report. Yes, it is a bug and I'm working on fixing it.

sergunSpb commented 10 years ago

Thanks a lot for your quick response.

trinitum commented 10 years ago

I just uploaded RedisDB-2.27 that should fix the problem on CPAN