Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add on_connect callback to Redis constructor
The on_connect callback will be called after each successful connection. Signed-off-by: Pedro Melo <melo@simplicidade.org>
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!perl | ||
|
||
use warnings; | ||
use strict; | ||
use Test::More; | ||
use Test::Fatal; | ||
use Redis; | ||
use lib 't/tlib'; | ||
use Test::SpawnRedisServer; | ||
|
||
my ($c, $srv) = redis(timeout => 1); | ||
END { $c->() if $c } | ||
|
||
subtest 'on_connect' => sub { | ||
my $r; | ||
ok($r = Redis->new(server => $srv, on_connect => sub { shift->incr('on_connect') }), | ||
'connected to our test redis-server'); | ||
is($r->get('on_connect'), 1, '... on_connect code was run'); | ||
|
||
ok($r = Redis->new(server => $srv, on_connect => sub { shift->incr('on_connect') }), | ||
'new connection is up and running'); | ||
is($r->get('on_connect'), 2, '... on_connect code was run again'); | ||
|
||
ok($r = Redis->new(reconnect => 1, server => $srv, on_connect => sub { shift->incr('on_connect') }), | ||
'new connection with reconnect enabled'); | ||
is($r->get('on_connect'), 3, '... on_connect code one again perfect'); | ||
|
||
$r->quit; | ||
is($r->get('on_connect'), 4, '... on_connect code works after reconnect also'); | ||
}; | ||
|
||
|
||
done_testing(); |