Permalink
Browse files

Add support for automatic AUTH command on connect:

If a password attr is given to new, Redis.pm will automatically send the
AUTH command after every connection.

First part of #11, but behaviour with auto-reconnect and tests still not
finished.

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
1 parent 273d2d4 commit b60d1a1b7706e45a888a85560aae430797d145f4 @melo melo committed Mar 12, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/Redis.pm
View
@@ -43,6 +43,8 @@ sub new {
}
}
+ $self->{password} = $args{password} if $args{password};
+
if ($args{sock}) {
$self->{server} = $args{sock};
$self->{builder} = sub { IO::Socket::UNIX->new($_[0]->{server}) };
@@ -420,6 +422,10 @@ sub __build_sock {
$self->{sock} = $self->{builder}->($self)
|| confess("Could not connect to Redis server at $self->{server}: $!");
+ ## FIXME: die on bad password, but what to do when in reconnect mode?
+ ## Abort reconnect? Really really die?
+ $self->auth($self->{password}) if exists $self->{password};
+
return;
}
@@ -827,6 +833,10 @@ trigger a retry until the new command is sent.
If we cannot re-establish a connection after C<< reconnect >> seconds,
an exception will be thrown.
+If your Redis server requires authentication, you can use the
+C<< password >> attribute. After each connection established, the Redis
+C<< AUTH >> command will be send to the server.
+
The C<< debug >> parameter enables debug information to STDERR,
including all interactions with the server. You can also enable debug
with the C<REDIS_DEBUG> environment variable.

0 comments on commit b60d1a1

Please sign in to comment.