Merge pull request #827 from cgagnaire/redis

add password option on rediscli custom mode
This commit is contained in:
qgarnier 2017-12-14 17:39:51 +01:00 committed by GitHub
commit 0a978bf718
1 changed files with 11 additions and 0 deletions

View File

@ -44,6 +44,7 @@ sub new {
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"password:s" => { name => 'password' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REDIS CLI OPTIONS', once => 1);
@ -81,6 +82,7 @@ sub check_options {
$self->{hostname} = $self->{option_results}->{hostname};
$self->{port} = $self->{option_results}->{port};
$self->{password} = $self->{option_results}->{password};
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname argument.");
@ -104,6 +106,9 @@ sub get_info {
my ($self, %options) = @_;
$self->{redis} = Redis->new(server => $self->{hostname} . ":" . $self->{port});
if (defined($self->{password})) {
$self->{redis}->auth($self->{password});
}
my $response = $self->{redis}->info;
my $items;
@ -111,6 +116,8 @@ sub get_info {
$items->{$attributes} = $response->{$attributes};
}
$self->{redis}->quit();
return $items;
}
@ -138,6 +145,10 @@ Redis hostname.
Redis port.
=item B<--password>
Redis password
=back
=head1 DESCRIPTION