File Coverage

blib/lib/Redis/Sentinel.pm
Criterion Covered Total %
statement 12 23 52.1
branch 0 6 0.0
condition n/a
subroutine 4 7 57.1
pod 3 3 100.0
total 19 39 48.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Redis
3             #
4             # This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
5             #
6             # This is free software, licensed under:
7             #
8             # The Artistic License 2.0 (GPL Compatible)
9             #
10             package Redis::Sentinel;
11             $Redis::Sentinel::VERSION = '2.000';
12             # ABSTRACT: Redis Sentinel interface
13              
14 15     15   103 use warnings;
  15         35  
  15         507  
15 15     15   90 use strict;
  15         35  
  15         311  
16              
17 15     15   70 use Carp;
  15         30  
  15         795  
18              
19 15     15   106 use base qw(Redis);
  15         28  
  15         4641  
20              
21             sub new {
22 0     0 1   my ($class, %args) = @_;
23             # these args are not allowed when contacting a sentinel
24 0           delete @args{qw(sentinels service)};
25              
26 0           $class->SUPER::new(%args);
27             }
28              
29             sub get_service_address {
30 0     0 1   my ($self, $service) = @_;
31 0           my ($ip, $port) = $self->sentinel('get-master-addr-by-name', $service);
32 0 0         defined $ip
33             or return;
34 0 0         $ip eq 'IDONTKNOW'
35             and return $ip;
36 0           return "$ip:$port";
37             }
38              
39             sub get_masters {
40 0 0   0 1   map { +{ @$_ }; } @{ shift->sentinel('masters') || [] };
  0            
  0            
41             }
42              
43             1;
44              
45             __END__