Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect behaviour differs from cpan Redis module #73

Closed
vsespb opened this issue Jan 10, 2018 · 3 comments
Closed

Reconnect behaviour differs from cpan Redis module #73

vsespb opened this issue Jan 10, 2018 · 3 comments

Comments

@vsespb
Copy link
Contributor

vsespb commented Jan 10, 2018

so, script:

use strict;
use warnings;
use Redis::Fast;
my $redis = Redis::Fast->new(
    server => 'localhost:6379',
    reconnect=>20,
    every => 100,
    cnx_timeout   => 10,
    read_timeout  => 3,
    write_timeout => 3,
);

while() {
    eval {
        $redis->get(42);
        print "works\n";
    } or do {
        print "err: $@"
    };
    sleep 1;
}

will print the following:

$ perl redispoc.pl 
works
works
works
works
works
err: Could not connect to Redis server at localhost:6379 at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.

if I stop redis server (after that first err: Could not connect to Redis server line emited), and then start it in a few minutes (after all reconnect attemts exhaused) $redis connect does not work even with live Redis server, it still emits "err: Not connected to any server".

In contrast behaviour with Redis module:

$ perl redispoc.pl 
works
works
works
works
works
works
works
works
works
err: Could not connect to Redis server at localhost:6379: Connection refused at /usr/local/share/perl/5.24.1/Redis.pm line 268.
	...propagated at /usr/local/share/perl/5.24.1/Redis.pm line 606.
err: Could not connect to Redis server at localhost:6379: Connection refused at /usr/local/share/perl/5.24.1/Redis.pm line 268.
	...propagated at /usr/local/share/perl/5.24.1/Redis.pm line 606.
works
works
works
works
works

i.e. the handle still can be used after redis server up.

Not sure which behaviour is more correct, but the fact is they differs.

Also our use case when we prefer Redis module behaviour:
we have long running daemons and if redis server down for several minutes we have to restart all daemons and cannot use reconnect feature, or we have to write special code in every eval after which we would want to connect again.

@shogo82148
Copy link
Owner

I think that because the every parameter is too short.
the unit of every is micro second, not milli second.

@vsespb
Copy link
Contributor Author

vsespb commented Jan 15, 2018

i've tried with 100_000. same:

$ perl 1.pl 
works
works
works
works
works
works
works
works
works
works
works
works
works
err: Could not connect to Redis server at localhost:6379 at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
err: Not connected to any server at /usr/local/lib/x86_64-linux-gnu/perl/5.24.1/Redis/Fast.pm line 265.
^C
$ cat 1.pl 
use strict;
use warnings;
use Redis::Fast;
my $redis = Redis::Fast->new(
    server => 'localhost:6379',
    reconnect=>20,
    every => 100_000,
    cnx_timeout   => 10,
    read_timeout  => 3,
    write_timeout => 3,
);

while() {
    eval {
        $redis->get(42);
        print "works\n";
    } or do {
        print "err: $@"
    };
    sleep 1;
}

shogo82148 added a commit that referenced this issue Jan 27, 2018
shogo82148 added a commit that referenced this issue Jan 28, 2018
add the reproduction test for #73
shogo82148 added a commit that referenced this issue Jan 28, 2018
Changelog diff is:

diff --git a/Changes b/Changes
index 65e5608..acf2fb3 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,9 @@ Revision history for Redis

 {{$NEXT}}

+0.21 2018-01-28T01:02:14Z
+    - Fix reconnect behaviour differs from cpan Redis module #73
+
 0.20 2017-02-25T22:48:26Z
     - Fix build issue on newer Perl
@shogo82148
Copy link
Owner

I fixed this issue, and released Redis::Fast v0.21.
Please try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants