Permalink
Browse files

Add name parameter to new(): sets the connection name (2.6.9+)

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
melo committed Jan 15, 2013
1 parent 7af9dd7 commit 38d7eaae77119b6c5fba947b4b78c5d4947bfa74
Showing with 14 additions and 0 deletions.
  1. +8 −0 lib/Redis.pm
  2. +6 −0 t/42-client_cmds.t
View
@@ -47,6 +47,14 @@ sub new {
$self->{password} = $args{password} if $args{password};
$self->{on_connect} = $args{on_connect} if $args{on_connect};
+ if (my $name = $args{name}) {
+ my $on_conn = $self->{on_connect};
+ $self->{on_connect} = sub {
+ $_[0]->client_setname($name);
+ $on_conn->(@_) if $on_conn;
+ }
+ }
+
if ($args{sock}) {
$self->{server} = $args{sock};
$self->{builder} = sub { IO::Socket::UNIX->new($_[0]->{server}) };
View
@@ -25,4 +25,10 @@ subtest 'client_{set|get}name commands' => sub {
};
+subtest 'client name via constructor' => sub {
+ ok(my $r = Redis->new(server => $srv, name => 'buuu'), 'connected to our test redis-server, with a name');
+ is($r->client_getname, 'buuu', '... name was properly set');
+};
+
+
done_testing();

0 comments on commit 38d7eaa

Please sign in to comment.