AnyEvent-Redis icon indicating copy to clipboard operation
AnyEvent-Redis copied to clipboard

Some some "subscription" event callback

Open basiliscos opened this issue 12 years ago • 0 comments

It is needed to have such an notification, when the subscription succeeds, and only then publish events (to be caught by subscriber).

The following test demonstrates the issue:

use strict;
use AnyEvent;
use Test::More;
use t::Redis;

test_redis {
    my $sub = shift;
    my $port = shift;

    my $info = $sub->info->recv;
    if($info->{redis_version} lt "1.3.10") {
      plan skip_all => "No PUBLISH/SUBSCRIBE support in this Redis version";
    }

    my $sub = AnyEvent::Redis->new(host => "127.0.0.1", port => $port);
    # umcomment the following to let the test pass
    # $sub->ping->recv;
    my $pub = AnyEvent::Redis->new(host => "127.0.0.1", port => $port);

    my $cv = AnyEvent->condvar;
    $sub->subscribe("test", sub {
            my($message, $chan) = @_;
            $cv->send(1);
        });
    $pub->publish("test", "test")->recv;
    my $guard = AnyEvent->timer(after => 5, cb => sub { $cv->send(0); });

    ok $cv->recv, "got published message";

    done_testing;
};

The test passed and fails time-to-time. If ping will be uncommented it will always succeed. But pingin isn't elegant solution.

Thanks.

basiliscos avatar Oct 19 '13 14:10 basiliscos