Redis.pm

filter: Statementstmt 44.9% 234 / 521 Branchbran 23.0% 64 / 278 Conditioncond 22.6% 33 / 146 MC/DCmcdc 1.1% 1 / 88 Subroutinesub 49.4% 43 / 87 Podpod 100% 16 / 16 totaltotal 34.4% 391 / 1136 CC 199 SCAR 38.5
CC
199
Cov
35%
__ANON__
272.0
new
164.0
__read_response_r
76.7
CRAP 46.8
↑ Summary Redis/Sentinel.pm »
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;
11 19 $Redis::VERSION = '2.000';
12 # ABSTRACT: Perl binding for Redis database
13 # VERSION
14 # AUTHORITY
15  
16 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 19 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use IO::Socket::UNIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use IO::Socket::Timeout;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 19 ▶use Fcntl qw( O_NONBLOCK F_SETFL );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 19 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 19 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 19 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 19 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 19 ▶use Redis::Sentinel;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 19 ▶use constant SSL_AVAILABLE => eval { require IO::Socket::SSL };
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 19 ▶use constant WIN32 => $^O =~ /mswin32/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 19 ▶use constant EWOULDBLOCK => eval {Errno::EWOULDBLOCK} || -1E9;
Subroutine BEGIN: called CC=2 SCAR=7.0
Condition50%1/2
eval { do { 11 } } || -1000000000.0
l!l
190
MC/DC0%0/1
eval { do { 11 } } || -1000000000.0
eval { do { 11 } }
Truth table50%1/2
A
A= eval { do { 11 } }
Aresult
11
00
37 19 ▶use constant EAGAIN => eval {Errno::EAGAIN} || -1E9;
Subroutine BEGIN: called CC=2 SCAR=7.0
Condition50%1/2
eval { do { 11 } } || -1000000000.0
l!l
190
MC/DC0%0/1
eval { do { 11 } } || -1000000000.0
eval { do { 11 } }
Truth table50%1/2
A
A= eval { do { 11 } }
Aresult
11
00
38 19 ▶use constant EINTR => eval {Errno::EINTR} || -1E9;
Subroutine BEGIN: called CC=2 SCAR=7.0
Condition50%1/2
eval { do { 4 } } || -1000000000.0
l!l
190
MC/DC0%0/1
eval { do { 4 } } || -1000000000.0
eval { do { 4 } }
Truth table50%1/2
A
A= eval { do { 4 } }
Aresult
11
00
39 19 ▶use constant ECONNRESET => eval {Errno::ECONNRESET} || -1E9;
Subroutine BEGIN: called CC=2 SCAR=7.0
Condition50%1/2
eval { do { 104 } } || -1000000000.0
l!l
190
MC/DC0%0/1
eval { do { 104 } } || -1000000000.0
eval { do { 104 } }
Truth table50%1/2
A
A= eval { do { 104 } }
Aresult
11
00
40  
41 # According to IO::Socket::SSL documentation, 16k is the maximum
42 # size of an SSL frame and because sysread returns data from only
43 # a single SSL frame you guarantee this way, that there is no pending
44 # data.
45 19 ▶use constant BUFSIZE => 16_384;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 2 ▶sub _maybe_enable_timeouts {
Subroutine _maybe_enable_timeouts: called CC=6 SCAR=19.9
48 2 my ($self, $socket) = @_;
49 2 ▶ $socket or return;
Branch: 1 branch
BranchTrueFalseTotal
$socket or return 2 0 2
50 defined $self->{read_timeout} || defined $self->{write_timeout}
51 2 ▶ or return $socket;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"read_timeout"} or defined $self->{"write_timeout"} or return $socket 2 0 2
Condition33%1/3
defined $self->{"read_timeout"} or defined $self->{"write_timeout"}
l!l&&r!l&&!r
200
MC/DC0%0/2
defined $self->{"read_timeout"} or defined $self->{"write_timeout"}
defined $self->{"read_timeout"} defined $self->{"write_timeout"}
Truth table33%1/3
A or B
A= defined $self->{"read_timeout"}B= defined $self->{"write_timeout"}
ABresult
1X1
011
000
52 2 IO::Socket::Timeout->enable_timeouts_on($socket);
53 defined $self->{read_timeout}
54 2 ▶ and $socket->read_timeout($self->{read_timeout});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"read_timeout"} and $socket->read_timeout($self->{"read_timeout"}) 2 0 2
55 defined $self->{write_timeout}
56 2 ▶ and $socket->write_timeout($self->{write_timeout});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"write_timeout"} and $socket->write_timeout($self->{"write_timeout"}) 0 2 2
57 2 $socket;
58 }
59  
60 2 ▶sub new {
Subroutine new: called CC=20 SCAR=51.0
Pod documented
61 2 my ($class, %args) = @_;
62 2 my $self = bless {}, $class;
63  
64 2 $self->{__buf} = '';
65 2 ▶ $self->{debug} = $args{debug} || $ENV{REDIS_DEBUG};
Condition33%1/3
$args{'debug'} || $ENV{'REDIS_DEBUG'}
l!l&&r!l&&!r
002
MC/DC0%0/2
$args{'debug'} || $ENV{'REDIS_DEBUG'}
$args{'debug'} $ENV{'REDIS_DEBUG'}
Truth table33%1/3
A || B
A= $args{'debug'}B= $ENV{'REDIS_DEBUG'}
ABresult
1X1
011
000
66  
67 ## Deal with REDIS_SERVER ENV
68 2 ▶ if ($ENV{REDIS_SERVER} && ! defined $args{sock} && ! defined $args{server} && ! defined $args{sentinels}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"REDIS_SERVER"} and not defined $args{"sock"} and not defined $args{"server"} and not defined $args{"sentinels"}) 0 2 2
Condition33%3/9
$ENV{"REDIS_SERVER"} and not defined $args{"sock"} and not defined $args{"server"} and not defined $args{"sentinels"}
!ll&&!rl&&r
200
$ENV{"REDIS_SERVER"} and not defined $args{"sock"} and not defined $args{"server"}
!ll&&!rl&&r
200
$ENV{"REDIS_SERVER"} and not defined $args{"sock"}
!ll&&!rl&&r
200
MC/DC0%0/4
$ENV{"REDIS_SERVER"} and not defined $args{"sock"} and not defined $args{"server"} and not defined $args{"sentinels"}
$ENV{"REDIS_SERVER"} not defined $args{"sock"} not defined $args{"server"} not defined $args{"sentinels"}
Truth table20%1/5
A and not(B) and not(C) and not(D)
A= $ENV{"REDIS_SERVER"}B= not defined $args{"sock"}C= not defined $args{"server"}D= not defined $args{"sentinels"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
69 0 ▶ if ($ENV{REDIS_SERVER} =~ m!^/!) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ENV{'REDIS_SERVER'} =~ m[^/]) { } 0 0 0
elsif ($ENV{'REDIS_SERVER'} =~ /^unix:(.+)/) { } 0 0 0
elsif ($ENV{'REDIS_SERVER'} =~ /^(?:tcp:)?(.+)/) { } 0 0 0
70 0 $args{sock} = $ENV{REDIS_SERVER};
71 }
72 elsif ($ENV{REDIS_SERVER} =~ m!^unix:(.+)!) {
73 0 $args{sock} = $1;
74 }
75 elsif ($ENV{REDIS_SERVER} =~ m!^(?:tcp:)?(.+)!) {
76 0 $args{server} = $1;
77 }
78 }
79  
80 defined $args{$_}
81 2 ▶ and $self->{$_} = $args{$_} for
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$_} and $self->{$_} = $args{$_} 2 28 30
82 qw(username password on_connect name no_auto_connect_on_new cnx_timeout
83 write_timeout read_timeout sentinels_ssl sentinels_username sentinels_password
84 sentinels_cnx_timeout sentinels_write_timeout sentinels_read_timeout no_sentinels_list_update);
85  
86 2 ▶ $self->{reconnect} = $args{reconnect} || 0;
Condition50%1/2
$args{'reconnect'} || 0
l!l
02
MC/DC0%0/1
$args{'reconnect'} || 0
$args{'reconnect'}
Truth table50%1/2
A
A= $args{'reconnect'}
Aresult
11
00
87 2 ▶ $self->{conservative_reconnect} = $args{conservative_reconnect} || 0;
Condition50%1/2
$args{'conservative_reconnect'} || 0
l!l
02
MC/DC0%0/1
$args{'conservative_reconnect'} || 0
$args{'conservative_reconnect'}
Truth table50%1/2
A
A= $args{'conservative_reconnect'}
Aresult
11
00
88 2 ▶ $self->{every} = $args{every} || 1000;
Condition50%1/2
$args{'every'} || 1000
l!l
02
MC/DC0%0/1
$args{'every'} || 1000
$args{'every'}
Truth table50%1/2
A
A= $args{'every'}
Aresult
11
00
89  
90 2 ▶ if (defined $args{sock}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'sock'}) { } 0 2 2
elsif ($args{'sentinels'}) { } 0 2 2
91 0 $self->{server} = $args{sock};
92 0 ▶ $self->{builder} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
93 0 my ($self) = @_;
94 $self->_maybe_enable_timeouts(
95 IO::Socket::UNIX->new(
96 Peer => $self->{server},
97 0 ▶ ( $self->{cnx_timeout} ? ( Timeout => $self->{cnx_timeout} ): () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'cnx_timeout'} ? : 0 0 0
98 )
99 );
100 0 };
101 } elsif ($args{sentinels}) {
102 0 $self->{sentinels} = $args{sentinels};
103  
104 0 ▶ ref $self->{sentinels} eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"sentinels"} eq "ARRAY" or croak("'sentinels' param must be an ArrayRef") 0 0 0
105 or croak("'sentinels' param must be an ArrayRef");
106  
107 defined($self->{service} = $args{service})
108 0 ▶ or croak("Need 'service' name when using 'sentinels'!");
Branch: 1 branch
BranchTrueFalseTotal
defined($self->{"service"} = $args{"service"}) or croak("Need 'service' name when using 'sentinels'!") 0 0 0
109  
110 0 ▶ $self->{builder} = sub {
Subroutine __ANON__: not called CC=16 SCAR=56.1
111 0 my ($self) = @_;
112 # try to connect to a sentinel
113 0 my $status;
114 0 foreach my $sentinel_address (@{$self->{sentinels}}) {
115 0 ▶ my $sentinel = eval {
Branch: 1 branch
BranchTrueFalseTotal
my $sentinel = eval { do { "Redis::Sentinel"->new("server", $sentinel_address, "username", $self->{"sentinels_username"}, "password", $self->{"sentinels_password"}, "cnx_timeout", defined $self->{"sentinels_cnx_timeout"} ? $self->{"sentinels_cnx_timeout"} : "0.1", "read_timeout", defined $self->{"sentinels_read_timeout"} ? $self->{"sentinels_read_timeout"} : 1, "write_timeout", defined $self->{"sentinels_write_timeout"} ? $self->{"sentinels_write_timeout"} : 1, "ssl", defined $self->{"sentinels_ssl"} ? $self->{"sentinels_ssl"} : 0) } } or next 0 0 0
116 Redis::Sentinel->new(
117 server => $sentinel_address,
118 username => $self->{sentinels_username},
119 password => $self->{sentinels_password},
120 cnx_timeout => ( defined $self->{sentinels_cnx_timeout}
121 ? $self->{sentinels_cnx_timeout} : 0.1 ),
122 read_timeout => ( defined $self->{sentinels_read_timeout}
123 ? $self->{sentinels_read_timeout} : 1 ),
124 write_timeout => ( defined $self->{sentinels_write_timeout}
125 ? $self->{sentinels_write_timeout} : 1 ),
126 ssl => ( defined $self->{sentinels_ssl}
127 0 ▶ ? $self->{sentinels_ssl} : 0 ),
Branch: 4 branches
BranchTrueFalseTotal
defined $self->{'sentinels_cnx_timeout'} ? : 0 0 0
defined $self->{'sentinels_read_timeout'} ? : 0 0 0
defined $self->{'sentinels_write_timeout'} ? : 0 0 0
defined $self->{'sentinels_ssl'} ? : 0 0 0
128 )
129 } or next;
130 0 my $server_address = $sentinel->get_service_address($self->{service});
131 0 ▶ defined $server_address
Branch: 1 branch
BranchTrueFalseTotal
defined $server_address or $status ||= "Sentinels don't know this service", next 0 0 0
Condition0%0/2
$status ||= "Sentinels don't know this service"
l!l
00
MC/DC0%0/1
$status ||= "Sentinels don't know this service"
$status
Truth table0%0/2
A
A= $status
Aresult
11
00
132 or $status ||= "Sentinels don't know this service",
133 next;
134 0 ▶ $server_address eq 'IDONTKNOW'
Branch: 1 branch
BranchTrueFalseTotal
$server_address eq "IDONTKNOW" and $status = "service is configured in one Sentinel, but was never reached", next 0 0 0
135 and $status = "service is configured in one Sentinel, but was never reached",
136 next;
137  
138 # we found the service, set the server
139 0 $self->{server} = $server_address;
140  
141 0 ▶ if (! $self->{no_sentinels_list_update} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_sentinels_list_update"}) 0 0 0
142 # move the elected sentinel at the front of the list and add
143 # additional sentinels
144 0 my $idx = 2;
145 0 my %h = ( ( map { $_ => $idx++ } @{$self->{sentinels}}),
146 $sentinel_address => 1,
147 );
148 $self->{sentinels} = [
149 0 ( sort { $h{$a} <=> $h{$b} } keys %h ), # sorted existing sentinels,
150 0 grep { ! $h{$_}; } # list of unknown
151 0 map { +{ @$_ }->{name}; } # names of
152 $sentinel->sentinel( # sentinels
153 sentinels => $self->{service} # for this service
154 )
155 0 ];
156 }
157  
158 0 my $socket_class;
159  
160 my %socket_args = (
161 PeerAddr => $server_address,
162 0 ▶ ( $self->{cnx_timeout} ? ( Timeout => $self->{cnx_timeout} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'cnx_timeout'} ? : 0 0 0
163 );
164  
165 0 ▶ if (exists $args{ssl} and $args{ssl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'ssl'} and $args{'ssl'}) { } 0 0 0
Condition0%0/3
exists $args{"ssl"} and $args{"ssl"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $args{"ssl"} and $args{"ssl"}
exists $args{"ssl"} $args{"ssl"}
Truth table0%0/3
A and B
A= exists $args{"ssl"}B= $args{"ssl"}
ABresult
0X0
100
111
166 0 if ( ! SSL_AVAILABLE ) {
167 croak("IO::Socket::SSL is required for connecting to Redis using SSL");
168 }
169  
170 0 $self->{ssl} = 1;
171 0 $socket_class = 'IO::Socket::SSL';
172 0 ▶ $socket_args{SSL_verify_mode} = $args{SSL_verify_mode} // 1;
Condition0%0/2
$args{"SSL_verify_mode"} // 1
l!l
00
MC/DC0%0/1
$args{"SSL_verify_mode"} // 1
$args{"SSL_verify_mode"}
Truth table0%0/2
A
A= $args{"SSL_verify_mode"}
Aresult
11
00
173 }
174 else {
175 0 $self->{ssl} = 0;
176 0 $socket_class = 'IO::Socket::INET';
177 }
178  
179 0 return $self->_maybe_enable_timeouts(
180 $socket_class->new(%socket_args)
181 );
182 }
183 0 ▶ croak($status || "failed to connect to any of the sentinels");
Condition0%0/2
$status || 'failed to connect to any of the sentinels'
l!l
00
MC/DC0%0/1
$status || 'failed to connect to any of the sentinels'
$status
Truth table0%0/2
A
A= $status
Aresult
11
00
184 0 };
185 } else {
186 2 ▶ $self->{server} = defined $args{server} ? $args{server} : '127.0.0.1:6379';
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'server'} ? : 2 0 2
187 2 ▶ $self->{builder} = sub {
Subroutine __ANON__: called CC=5 SCAR=18.0
188 2 my ($self) = @_;
189  
190 2 my $socket_class;
191  
192 my %socket_args = (
193 PeerAddr => $self->{server},
194 2 ▶ ( $self->{cnx_timeout} ? ( Timeout => $self->{cnx_timeout} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'cnx_timeout'} ? : 0 2 2
195 );
196  
197 2 ▶ if (exists $args{ssl} and $args{ssl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'ssl'} and $args{'ssl'}) { } 2 0 2
Condition33%1/3
exists $args{"ssl"} and $args{"ssl"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $args{"ssl"} and $args{"ssl"}
exists $args{"ssl"} $args{"ssl"}
Truth table33%1/3
A and B
A= exists $args{"ssl"}B= $args{"ssl"}
ABresult
0X0
100
111
198 2 if ( ! SSL_AVAILABLE ) {
199 croak("IO::Socket::SSL is required for connecting to Redis using SSL");
200 }
201  
202 2 $self->{ssl} = 1;
203 2 $socket_class = 'IO::Socket::SSL';
204 2 ▶ $socket_args{SSL_verify_mode} = $args{SSL_verify_mode} // 1;
Condition50%1/2
$args{"SSL_verify_mode"} // 1
l!l
20
MC/DC0%0/1
$args{"SSL_verify_mode"} // 1
$args{"SSL_verify_mode"}
Truth table50%1/2
A
A= $args{"SSL_verify_mode"}
Aresult
11
00
205 }
206 else {
207 0 $self->{ssl} = 0;
208 0 $socket_class = 'IO::Socket::INET';
209 }
210  
211 2 return $self->_maybe_enable_timeouts(
212 $socket_class->new(%socket_args)
213 );
214 2 };
215 }
216  
217 2 $self->{is_subscriber} = 0;
218 2 $self->{subscribers} = {};
219  
220 2 ▶ $self->connect unless $args{no_auto_connect_on_new};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"no_auto_connect_on_new"} 2 0 2
221  
222 2 return $self;
223 }
224  
225 0 ▶sub is_subscriber { $_[0]{is_subscriber} }
Subroutine is_subscriber: not called CC=1 SCAR=6.9
Pod documented
226  
227 0 ▶sub select {
Subroutine select: not called CC=4 SCAR=30.0
Pod documented
228 0 my $self = shift;
229 0 my $database = shift;
230  
231 0 ▶ croak( "Cannot select an undefined redis database" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $database 0 0 0
232 unless defined $database;
233 # don't want to send multiple select() back and forth
234 0 ▶ if (!defined $self->{current_database} or $self->{current_database} ne $database) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"current_database"} or $self->{"current_database"} ne $database) 0 0 0
Condition0%0/3
not defined $self->{"current_database"} or $self->{"current_database"} ne $database
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->{"current_database"} or $self->{"current_database"} ne $database
not defined $self->{"current_database"} $self->{"current_database"} ne $database
Truth table0%0/3
not(A) or B
A= not defined $self->{"current_database"}B= $self->{"current_database"} ne $database
ABresult
1X1
011
000
235 0 my $ret = $self->__std_cmd('select', $database, @_);
236 0 $self->{current_database} = $database;
237 0 return $ret;
238 };
239 0 return "OK"; # emulate redis response as of 3.0.6 just in case anybody cares
240 }
241  
242 ### we don't want DESTROY to fallback into AUTOLOAD
243 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
244  
245  
246 ### Deal with common, general case, Redis commands
247 19 our $AUTOLOAD;
248  
249 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
250 1 my $command = $AUTOLOAD;
251 1 $command =~ s/.*://;
252  
253 1 ▶ my $method = sub { shift->__std_cmd($command, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
254  
255 # Save this method for future calls
256 19 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
257 1 *$AUTOLOAD = $method;
258  
259 1 goto $method;
260 }
261  
262 2 ▶sub __std_cmd {
Subroutine __std_cmd: called CC=10 SCAR=32.5
263 2 my $self = shift;
264 2 my $command = shift;
265  
266 2 $self->__is_valid_command($command);
267  
268 2 ▶ my $cb = @_ && ref $_[-1] eq 'CODE' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] eq 'CODE' ? : 0 2 2
Condition33%1/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
020
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table33%1/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
269  
270 # If this is an EXEC command, in pipelined mode, and one of the commands
271 # executed in the transaction yields an error, we must collect all errors
272 # from that command, rather than throwing an exception immediately.
273 2 my $uc_command = uc($command);
274 2 ▶ my $collect_errors = $cb && $uc_command eq 'EXEC';
Condition33%1/3
$cb && $uc_command eq 'EXEC'
!ll&&!rl&&r
200
MC/DC0%0/2
$cb && $uc_command eq 'EXEC'
$cb $uc_command eq 'EXEC'
Truth table33%1/3
A && B
A= $cbB= $uc_command eq 'EXEC'
ABresult
0X0
100
111
275  
276 2 ▶ if ($uc_command eq 'MULTI') {
Branch: 4 branches
BranchTrueFalseTotal
if ($uc_command eq 'MULTI') { } 0 2 2
elsif ($uc_command eq 'EXEC' or $uc_command eq 'DISCARD') { } 0 2 2
elsif ($uc_command eq 'WATCH') { } 0 2 2
elsif ($uc_command eq 'UNWATCH') { } 0 2 2
277 0 $self->{__inside_transaction} = 1;
278 ▶ } elsif ($uc_command eq 'EXEC' || $uc_command eq 'DISCARD') {
Condition33%1/3
$uc_command eq "EXEC" or $uc_command eq "DISCARD"
l!l&&r!l&&!r
002
MC/DC0%0/2
$uc_command eq "EXEC" or $uc_command eq "DISCARD"
$uc_command eq "EXEC" $uc_command eq "DISCARD"
Truth table33%1/3
A or B
A= $uc_command eq "EXEC"B= $uc_command eq "DISCARD"
ABresult
1X1
011
000
279 0 delete $self->{__inside_transaction};
280 0 delete $self->{__inside_watch};
281 } elsif ($uc_command eq 'WATCH') {
282 0 $self->{__inside_watch} = 1;
283 } elsif ($uc_command eq 'UNWATCH') {
284 0 delete $self->{__inside_watch};
285 }
286  
287 ## Fast path, no reconnect;
288 $self->{reconnect}
289 2 ▶ or return $self->__run_cmd($command, $collect_errors, undef, $cb, @_);
Branch: 1 branch
BranchTrueFalseTotal
$self->{"reconnect"} or return $self->__run_cmd($command, $collect_errors, undef, $cb, @_) 0 2 2
290  
291 0 my @cmd_args = @_;
292 $self->__with_reconnect(
293 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
294 0 $self->__run_cmd($command, $collect_errors, undef, $cb, @cmd_args);
295 }
296 0 );
297 }
298  
299 0 ▶sub __with_reconnect {
Subroutine __with_reconnect: not called CC=2 SCAR=17.9
300 0 my ($self, $cb) = @_;
301  
302 ## Fast path, no reconnect
303 $self->{reconnect}
304 0 ▶ or return $cb->();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"reconnect"} or return &$cb() 0 0 0
305  
306 return &try(
307 $cb,
308 0 ▶ catch {
Subroutine __ANON__: not called CC=7 SCAR=40.3
309 0 ▶ ref($_) eq 'Redis::X::Reconnect'
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "Redis::X::Reconnect" or die $_ 0 0 0
310 or die $_;
311  
312 $self->{__inside_transaction} || $self->{__inside_watch}
313 0 ▶ and croak("reconnect disabled inside transaction or watch");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"__inside_transaction"} || $self->{"__inside_watch"} and croak("reconnect disabled inside transaction or watch") 0 0 0
Condition0%0/3
$self->{"__inside_transaction"} or $self->{"__inside_watch"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"__inside_transaction"} or $self->{"__inside_watch"}
$self->{"__inside_transaction"} $self->{"__inside_watch"}
Truth table0%0/3
A or B
A= $self->{"__inside_transaction"}B= $self->{"__inside_watch"}
ABresult
1X1
011
000
314  
315 0 ▶ scalar @{$self->{queue} || []} && $self->{conservative_reconnect}
Condition0%0/2
$self->{'queue'} || []
l!l
00
MC/DC0%0/1
$self->{'queue'} || []
$self->{'queue'}
Truth table0%0/2
A
A= $self->{'queue'}
Aresult
11
00
316 0 ▶ and croak("reconnect disabled while responses are pending and conservative reconnect mode enabled");
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$self->{"queue"} or [];} and $self->{"conservative_reconnect"} and croak("reconnect disabled while responses are pending and conservative reconnect mode enabled") 0 0 0
Condition0%0/3
scalar @{$self->{"queue"} or [];} and $self->{"conservative_reconnect"}
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @{$self->{"queue"} or [];} and $self->{"conservative_reconnect"}
scalar @{$self->{"queue"} or [];} $self->{"conservative_reconnect"}
Truth table0%0/3
A and B
A= scalar @{$self->{"queue"} or [];}B= $self->{"conservative_reconnect"}
ABresult
0X0
100
111
317  
318 0 $self->connect;
319 0 $cb->();
320 }
321 0 );
322 }
323  
324 2 ▶sub __run_cmd {
Subroutine __run_cmd: called CC=8 SCAR=24.8
325 2 my ($self, $command, $collect_errors, $custom_decode, $cb, @args) = @_;
326  
327 2 my $ret;
328 my $wrapper = $cb && $custom_decode
329 0 ▶ ? sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
330 0 my ($reply, $error) = @_;
331 0 $cb->(scalar $custom_decode->($reply), $error);
332 }
333 1 ▶ : $cb || sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
334 1 my ($reply, $error) = @_;
335 1 ▶ croak "[$command] $error, " if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 1 1
336 1 $ret = $reply;
337 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$cb && $custom_decode ? : 0 2 2
Condition33%2/6
$cb and $custom_decode
!ll&&!rl&&r
200
$cb or sub { my($reply, $error) = @_; croak("[$command] $error, ") if defined $error; $ret = $reply; }
l!l&&r!l&&!r
020
MC/DC0%0/2
$cb and $custom_decode
$cb $custom_decode
MC/DC0%0/2
$cb or sub { my($reply, $error) = @_; croak("[$command] $error, ") if defined $error; $ret = $reply; }
$cb sub { my($reply, $error) = @_; croak("[$command] $error, ") if defined $error; $ret = $reply; }
Truth table33%1/3
A and B
A= $cbB= $custom_decode
ABresult
0X0
100
111
Truth table33%1/3
A or B
A= $cbB= sub { my($reply, $error) = @_; croak("[$command] $error, ") if defined $error; $ret = $reply; }
ABresult
1X1
011
000
338  
339 2 $self->__send_command($command, @args);
340 2 push @{ $self->{queue} }, [$command, $wrapper, $collect_errors];
341  
342 2 ▶ return 1 if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 2 2
343  
344 2 $self->wait_all_responses;
345 return
346 1 ▶ $custom_decode ? $custom_decode->($ret, !wantarray)
Branch: 2 branches
BranchTrueFalseTotal
$custom_decode ? : 0 1 1
wantarray && ref $ret eq 'ARRAY' ? : 0 1 1
Condition33%1/3
wantarray and ref $ret eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
wantarray and ref $ret eq "ARRAY"
wantarray ref $ret eq "ARRAY"
Truth table33%1/3
A and B
A= wantarrayB= ref $ret eq "ARRAY"
ABresult
0X0
100
111
347 : wantarray && ref $ret eq 'ARRAY' ? @$ret
348 : $ret;
349 }
350  
351 2 ▶sub wait_all_responses {
Subroutine wait_all_responses: called CC=2 SCAR=6.9
Pod documented
352 2 my ($self) = @_;
353  
354 2 my $queue = $self->{queue};
355 2 ▶ $self->wait_one_response while @$queue;
Branch: 1 branch
BranchTrueFalseTotal
@$queue and do { $self->wait_one_response } 2 1 3
356  
357 1 return;
358 }
359  
360 2 ▶sub wait_one_response {
Subroutine wait_one_response: called CC=2 SCAR=7.0
Pod documented
361 2 my ($self) = @_;
362  
363 2 my $handler = shift @{ $self->{queue} };
364 2 ▶ return unless $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 2 2
365  
366 2 my ($command, $cb, $collect_errors) = @$handler;
367 2 $cb->($self->__read_response($command, $collect_errors));
368  
369 1 return;
370 }
371  
372  
373 ### Commands with extra logic
374 0 ▶sub quit {
Subroutine quit: not called CC=4 SCAR=30.0
Pod documented
375 0 my ($self) = @_;
376 0 ▶ return unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 0 0
377  
378 0 ▶ croak "[quit] only works in synchronous mode, "
Branch: 1 branch
BranchTrueFalseTotal
if @_ and ref $_[-1] eq "CODE" 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
379 if @_ && ref $_[-1] eq 'CODE';
380  
381 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
382 0 $self->wait_all_responses;
383 0 $self->__send_command('QUIT');
384 0 };
385  
386 0 $self->__close_sock();
387  
388 0 return 1;
389 }
390  
391 0 ▶sub shutdown {
Subroutine shutdown: not called CC=5 SCAR=34.0
Pod documented
392 0 my ($self) = @_;
393 0 $self->__is_valid_command('SHUTDOWN');
394  
395 0 ▶ croak "[shutdown] only works in synchronous mode, "
Branch: 1 branch
BranchTrueFalseTotal
if @_ and ref $_[-1] eq "CODE" 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
396 if @_ && ref $_[-1] eq 'CODE';
397  
398 0 ▶ return unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 0 0
399  
400 0 $self->wait_all_responses;
401 0 $self->__send_command('SHUTDOWN');
402 0 ▶ $self->__close_sock() || croak("Can't close socket: $!");
Branch: 1 branch
BranchTrueFalseTotal
$self->__close_sock or croak("Can't close socket: $!") 0 0 0
403  
404 0 return 1;
405 }
406  
407 0 ▶sub ping {
Subroutine ping: not called CC=4 SCAR=30.0
Pod documented
408 0 my $self = shift;
409 0 $self->__is_valid_command('PING');
410  
411 0 ▶ croak "[ping] only works in synchronous mode, "
Branch: 1 branch
BranchTrueFalseTotal
if @_ and ref $_[-1] eq "CODE" 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
412 if @_ && ref $_[-1] eq 'CODE';
413  
414 0 ▶ return unless defined $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"sock"} 0 0 0
415  
416 0 $self->wait_all_responses;
417 0 ▶ return scalar try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
418 0 $self->__std_cmd('PING');
419 }
420 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
421 0 $self->__close_sock();
422 0 return;
423 0 };
424 }
425  
426 0 ▶sub info {
Subroutine info: not called CC=4 SCAR=30.0
Pod documented
427 0 my $self = shift;
428 0 $self->__is_valid_command('INFO');
429  
430 0 ▶ my $custom_decode = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
431 0 my ($reply) = @_;
432 0 ▶ return $reply if !defined $reply || ref $reply;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $reply or ref $reply 0 0 0
Condition0%0/3
not defined $reply or ref $reply
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $reply or ref $reply
not defined $reply ref $reply
Truth table0%0/3
not(A) or B
A= not defined $replyB= ref $reply
ABresult
1X1
011
000
433 0 return { map { split(/:/, $_, 2) } grep {/^[^#]/} split(/\r\n/, $reply) };
434 0 };
435  
436 0 ▶ my $cb = @_ && ref $_[-1] eq 'CODE' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] eq 'CODE' ? : 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
437  
438 ## Fast path, no reconnect
439 return $self->__run_cmd('INFO', 0, $custom_decode, $cb, @_)
440 0 ▶ unless $self->{reconnect};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"reconnect"} 0 0 0
441  
442 0 my @cmd_args = @_;
443 $self->__with_reconnect(
444 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
445 0 $self->__run_cmd('INFO', 0, $custom_decode, $cb, @cmd_args);
446 }
447 0 );
448 }
449  
450 0 ▶sub keys {
Subroutine keys: not called CC=4 SCAR=30.0
Pod documented
451 0 my $self = shift;
452 0 $self->__is_valid_command('KEYS');
453  
454 0 ▶ my $custom_decode = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
455 0 my ($reply, $synchronous_scalar) = @_;
456  
457 ## Support redis <= 1.2.6
458 0 ▶ $reply = [split(/\s/, $reply)] if defined $reply && !ref $reply;
Branch: 1 branch
BranchTrueFalseTotal
if defined $reply and not ref $reply 0 0 0
Condition0%0/3
defined $reply and not ref $reply
!ll&&!rl&&r
000
MC/DC0%0/2
defined $reply and not ref $reply
defined $reply not ref $reply
Truth table0%0/3
A and not(B)
A= defined $replyB= not ref $reply
ABresult
0X0
100
111
459  
460 0 ▶ return ref $reply && ($synchronous_scalar || wantarray) ? @$reply : $reply;
Branch: 1 branch
BranchTrueFalseTotal
ref $reply && ($synchronous_scalar || wantarray) ? : 0 0 0
Condition0%0/6
ref $reply and $synchronous_scalar || wantarray
!ll&&!rl&&r
000
$synchronous_scalar or wantarray
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $reply and $synchronous_scalar || wantarray
ref $reply $synchronous_scalar wantarray
Truth table0%0/4
A and B or C
A= ref $replyB= $synchronous_scalarC= wantarray
ABCresult
0XX0
1000
11X1
1011
461 0 };
462  
463 0 ▶ my $cb = @_ && ref $_[-1] eq 'CODE' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] eq 'CODE' ? : 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "CODE"
@_ ref $_[-1] eq "CODE"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "CODE"
ABresult
0X0
100
111
464  
465 ## Fast path, no reconnect
466 return $self->__run_cmd('KEYS', 0, $custom_decode, $cb, @_)
467 0 ▶ unless $self->{reconnect};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"reconnect"} 0 0 0
468  
469 0 my @cmd_args = @_;
470 $self->__with_reconnect(
471 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
472 0 $self->__run_cmd('KEYS', 0, $custom_decode, $cb, @cmd_args);
473 }
474 0 );
475 }
476  
477  
478 ### PubSub
479 0 ▶sub wait_for_messages {
Subroutine wait_for_messages: not called CC=3 SCAR=24.8
Pod documented
480 0 my ($self, $timeout) = @_;
481  
482 0 my $s = IO::Select->new;
483  
484 0 my $count = 0;
485  
486  
487 0 my $e;
488  
489 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
490 0 ▶ $self->__with_reconnect( sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
491  
492 # the socket can be changed due to reconnection, so get it each time
493 0 my $sock = $self->{sock};
494 0 $s->remove($s->handles);
495 0 $s->add($sock);
496  
497 0 ▶ while ($s->can_read($timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->can_read($timeout)) 0 0 0
498 0 my $has_stuff = $self->__try_read_sock($sock);
499 # If the socket is ready to read but there is nothing to read, ( so
500 # it's an EOF ), try to reconnect.
501 0 ▶ defined $has_stuff
Branch: 1 branch
BranchTrueFalseTotal
defined $has_stuff or $self->__throw_reconnect("EOF from server") 0 0 0
502 or $self->__throw_reconnect('EOF from server');
503  
504 0 my $cond;
505  
506 0 ▶ if ( ! $self->{ssl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'ssl'}) { } 0 0 0
507 0 ▶ $cond = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
508 # if __try_read_sock() return 0 (no data)
509 # or undef ( socket became EOF), back to select until timeout
510 0 ▶ return $self->{__buf} || $self->__try_read_sock($sock);
Condition0%0/3
$self->{'__buf'} || $self->__try_read_sock($sock)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'__buf'} || $self->__try_read_sock($sock)
$self->{'__buf'} $self->__try_read_sock($sock)
Truth table0%0/3
A || B
A= $self->{'__buf'}B= $self->__try_read_sock($sock)
ABresult
1X1
011
000
511 }
512 0 } else {
513 0 ▶ $cond = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
514 # continue if there is still some data left. If the buffer is
515 # larger than 16K, there won't be any pending data left though
516 0 ▶ return $self->{__buf} || $sock->pending;
Condition0%0/3
$self->{'__buf'} || $sock->pending
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'__buf'} || $sock->pending
$self->{'__buf'} $sock->pending
Truth table0%0/3
A || B
A= $self->{'__buf'}B= $sock->pending
ABresult
1X1
011
000
517 }
518 0 }
519  
520 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
&$cond() and do { do { () = $self->__read_response("WAIT_FOR_MESSAGES"); croak("[WAIT_FOR_MESSAGES] $error, ") if defined $error; $self->__process_pubsub_msg($reply); ++$count } } 0 0 0
521 0 my ($reply, $error) = $self->__read_response('WAIT_FOR_MESSAGES');
522 0 ▶ croak "[WAIT_FOR_MESSAGES] $error, " if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
523 0 $self->__process_pubsub_msg($reply);
524 0 $count++;
525  
526 } while ($cond->());
527 }
528  
529 0 });
530  
531 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
532 0 $e = $_;
533 0 };
534  
535 # if We had an error and it was not an EOF, die
536 0 ▶defined $e && $e ne 'EOF from server'
Branch: 1 branch
BranchTrueFalseTotal
defined $e and $e ne "EOF from server" and die $e 0 0 0
Condition0%0/3
defined $e and $e ne "EOF from server"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and $e ne "EOF from server"
defined $e $e ne "EOF from server"
Truth table0%0/3
A and B
A= defined $eB= $e ne "EOF from server"
ABresult
0X0
100
111
537 and die $e;
538  
539 0 return $count;
540 }
541  
542 0 ▶sub __subscription_cmd {
Subroutine __subscription_cmd: not called CC=2 SCAR=17.9
543 0 my $self = shift;
544 0 my $pr = shift;
545 0 my $unsub = shift;
546 0 my $command = shift;
547 0 my $cb = pop;
548  
549 0 ▶ croak("Missing required callback in call to $command(), ")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 0 0
550 unless ref($cb) eq 'CODE';
551  
552 0 $self->wait_all_responses;
553  
554 0 my @subs = @_;
555 $self->__with_reconnect(
556 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
557 $self->__throw_reconnect('Not connected to any server')
558 0 ▶ unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 0 0
559  
560 0 ▶ @subs = $self->__process_unsubscribe_requests($cb, $pr, @subs)
Branch: 1 branch
BranchTrueFalseTotal
if $unsub 0 0 0
561 if $unsub;
562 0 ▶ return unless @subs;
Branch: 1 branch
BranchTrueFalseTotal
unless @subs 0 0 0
563  
564 0 $self->__send_command($command, @subs);
565  
566 0 my %cbs = map { ("${pr}message:$_" => $cb) } @subs;
567 0 return $self->__process_subscription_changes($command, \%cbs);
568 }
569 0 );
570 }
571  
572 0 ▶sub subscribe { shift->__subscription_cmd('', 0, subscribe => @_) }
Subroutine subscribe: not called CC=1 SCAR=6.9
Pod documented
573 0 ▶sub psubscribe { shift->__subscription_cmd('p', 0, psubscribe => @_) }
Subroutine psubscribe: not called CC=1 SCAR=6.9
Pod documented
574 0 ▶sub unsubscribe { shift->__subscription_cmd('', 1, unsubscribe => @_) }
Subroutine unsubscribe: not called CC=1 SCAR=6.9
Pod documented
575 0 ▶sub punsubscribe { shift->__subscription_cmd('p', 1, punsubscribe => @_) }
Subroutine punsubscribe: not called CC=1 SCAR=6.9
Pod documented
576  
577 0 ▶sub __process_unsubscribe_requests {
Subroutine __process_unsubscribe_requests: not called CC=3 SCAR=24.8
578 0 my ($self, $cb, $pr, @unsubs) = @_;
579 0 my $subs = $self->{subscribers};
580  
581 0 my @subs_to_unsubscribe;
582 0 for my $sub (@unsubs) {
583 0 my $key = "${pr}message:$sub";
584 0 my $cbs = $subs->{$key} = [grep { $_ ne $cb } @{ $subs->{$key} }];
585 0 ▶ next if @$cbs;
Branch: 1 branch
BranchTrueFalseTotal
if @$cbs 0 0 0
586  
587 0 delete $subs->{$key};
588 0 push @subs_to_unsubscribe, $sub;
589 }
590  
591 0 return @subs_to_unsubscribe;
592 }
593  
594 0 ▶sub __process_subscription_changes {
Subroutine __process_subscription_changes: not called CC=5 SCAR=34.0
595 0 my ($self, $cmd, $expected) = @_;
596 0 my $subs = $self->{subscribers};
597  
598 0 ▶ while (%$expected) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$expected) 0 0 0
599 0 my ($m, $error) = $self->__read_response($cmd);
600 0 ▶ croak "[$cmd] $error, " if defined $error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
601  
602 ## Deal with pending PUBLISH'ed messages
603 0 ▶ if ($m->[0] =~ /^p?message$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->[0] =~ /^p?message$/) 0 0 0
604 0 $self->__process_pubsub_msg($m);
605 0 next;
606 }
607  
608 0 my ($key, $unsub) = $m->[0] =~ m/^(p)?(un)?subscribe$/;
609 0 $key .= "message:$m->[1]";
610 0 my $cb = delete $expected->{$key};
611  
612 0 ▶ push @{ $subs->{$key} }, $cb unless $unsub;
Branch: 1 branch
BranchTrueFalseTotal
unless $unsub 0 0 0
613  
614 0 $self->{is_subscriber} = $m->[2];
615 }
616 }
617  
618 0 ▶sub __process_pubsub_msg {
Subroutine __process_pubsub_msg: not called CC=4 SCAR=30.0
619 0 my ($self, $m) = @_;
620 0 my $subs = $self->{subscribers};
621  
622 0 my $sub = $m->[1];
623 0 my $cbid = "$m->[0]:$sub";
624 0 my $data = pop @$m;
625 0 ▶ my $topic = defined $m->[2] ? $m->[2] : $sub;
Branch: 1 branch
BranchTrueFalseTotal
defined $m->[2] ? : 0 0 0
626  
627 0 ▶ if (!defined $subs->{$cbid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subs->{$cbid}) 0 0 0
628 0 warn "Message for topic '$topic' ($cbid) without expected callback, ";
629 0 return;
630 }
631  
632 0 $_->($data, $topic, $sub) for @{ $subs->{$cbid} };
633  
634 0 return 1;
635  
636 }
637  
638  
639 ### Mode validation
640 2 ▶sub __is_valid_command {
Subroutine __is_valid_command: called CC=2 SCAR=7.2
641 2 my ($self, $cmd) = @_;
642  
643 croak("Cannot use command '$cmd' while in SUBSCRIBE mode, ")
644 2 ▶ if $self->{is_subscriber};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_subscriber"} 0 2 2
645 }
646  
647  
648 ### Socket operations
649 2 ▶sub connect {
Subroutine connect: called CC=4 SCAR=20.9
Pod documented
650 2 my ($self) = @_;
651 2 delete $self->{sock};
652 2 delete $self->{__inside_watch};
653 2 delete $self->{__inside_transaction};
654  
655 # Suppose we have at least one command response pending, but we're about
656 # to reconnect. The new connection will never get a response to any of
657 # the pending commands, so delete all those pending responses now.
658 2 $self->{queue} = [];
659 2 $self->{pid} = $$;
660  
661 ## Fast path, no reconnect
662 2 ▶ return $self->__build_sock() unless $self->{reconnect};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"reconnect"} 2 0 2
663  
664 ## Use precise timers on reconnections
665 0 require Time::HiRes;
666 0 my $t0 = [Time::HiRes::gettimeofday()];
667  
668 ## Reconnect...
669 0 while (1) {
670 0 eval { $self->__build_sock };
671  
672 0 ▶ last unless $@; ## Connected!
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
673 0 ▶ die if Time::HiRes::tv_interval($t0) > $self->{reconnect}; ## Timeout
Branch: 1 branch
BranchTrueFalseTotal
if Time::HiRes::tv_interval($t0) > $self->{"reconnect"} 0 0 0
674 0 Time::HiRes::usleep($self->{every}); ## Retry in...
675 }
676  
677 0 return;
678 }
679  
680 2 ▶sub __build_sock {
Subroutine __build_sock: called CC=7 SCAR=27.9
681 2 my ($self) = @_;
682  
683 do {
684 2 $self->{sock} = $self->{builder}->($self);
685 2 ▶ } while (!$self->{sock} && $! == Errno::EINTR);
Branch: 1 branch
BranchTrueFalseTotal
not $self->{"sock"} and $! == 4 and do { do { $self->{"sock"} = $self->{"builder"}->($self) } } 0 2 2
Condition33%1/3
not $self->{"sock"} and $! == 4
!ll&&!rl&&r
200
MC/DC0%0/2
not $self->{"sock"} and $! == 4
not $self->{"sock"} $! == 4
Truth table33%1/3
not(A) and B
A= not $self->{"sock"}B= $! == 4
ABresult
0X0
100
111
686  
687 2 ▶ unless ($self->{sock}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sock"}) 0 2 2
688 0 croak("Could not connect to Redis server at $self->{server}: $!");
689 }
690  
691 2 $self->{__buf} = '';
692  
693 2 ▶ if (defined $self->{username} && defined $self->{password}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'username'} and defined $self->{'password'}) { } 0 2 2
elsif (defined $self->{'password'}) { } 0 2 2
Condition33%1/3
defined $self->{"username"} and defined $self->{"password"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $self->{"username"} and defined $self->{"password"}
defined $self->{"username"} defined $self->{"password"}
Truth table33%1/3
A and B
A= defined $self->{"username"}B= defined $self->{"password"}
ABresult
0X0
100
111
694 0 ▶ try { $self->auth($self->{username}, $self->{password}) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
695 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
696 0 my $error = $_;
697 0 $self->{reconnect} = 0;
698 0 croak('Redis server authentication error: ' . $error);
699 0 };
700 } elsif (defined $self->{password}) {
701 0 ▶ try { $self->auth($self->{password}) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
702 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
703 0 my $error = $_;
704 0 $self->{reconnect} = 0;
705 0 croak('Redis server authentication error: ' . $error);
706 0 };
707 }
708  
709 2 $self->__on_connection;
710  
711 2 return;
712 }
713  
714 1 ▶sub __close_sock {
Subroutine __close_sock: called CC=2 SCAR=7.0
715 1 my ($self) = @_;
716 1 $self->{__buf} = '';
717 1 delete $self->{__inside_watch};
718 1 delete $self->{__inside_transaction};
719 1 ▶ defined $self->{sock} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"sock"} or return 1 1 0 1
720 1 return close(delete $self->{sock});
721 }
722  
723 2 ▶sub __on_connection {
Subroutine __on_connection: called CC=10 SCAR=38.5
724  
725 2 my ($self) = @_;
726  
727 # If we are in PubSub mode we shouldn't perform any command besides
728 # (p)(un)subscribe
729 2 ▶ if (! $self->{is_subscriber}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"is_subscriber"}) 2 0 2
730 defined $self->{name}
731 0 ▶ and try {
Subroutine __ANON__: not called CC=3 SCAR=24.8
732 0 my $n = $self->{name};
733 0 ▶ $n = $n->($self) if ref($n) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $n eq "CODE" 0 0 0
734 0 ▶ $self->client_setname($n) if defined $n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 0 0 0
735 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"name"} and &try(sub { my $n = $self->{"name"}; $n = &$n($self) if ref $n eq "CODE"; $self->client_setname($n) if defined $n; } ) 0 2 2
736  
737 # don't use select() function as it's caching database name,
738 # rather call select directly
739 defined $self->{current_database}
740 2 ▶ and $self->__std_cmd('select', $self->{current_database});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"current_database"} and $self->__std_cmd("select", $self->{"current_database"}) 0 2 2
741 }
742  
743 2 foreach my $topic (CORE::keys(%{$self->{subscribers}})) {
744 0 ▶ if ($topic =~ /(p?message):(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($topic =~ /(p?message):(.*)$/) 0 0 0
745 0 my ($key, $channel) = ($1, $2);
746 0 ▶ if ($key eq 'message') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'message') { } 0 0 0
747 0 $self->__send_command('subscribe', $channel);
748 0 my (undef, $error) = $self->__read_response('subscribe');
749 0 ▶ defined $error
Branch: 1 branch
BranchTrueFalseTotal
defined $error and croak("[subscribe] $error") 0 0 0
750 and croak "[subscribe] $error";
751 } else {
752 0 $self->__send_command('psubscribe', $channel);
753 0 my (undef, $error) = $self->__read_response('psubscribe');
754 0 ▶ defined $error
Branch: 1 branch
BranchTrueFalseTotal
defined $error and croak("[psubscribe] $error") 0 0 0
755 and croak "[psubscribe] $error";
756 }
757 }
758 }
759  
760 defined $self->{on_connect}
761 2 ▶ and $self->{on_connect}->($self);
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"on_connect"} and $self->{"on_connect"}->($self) 0 2 2
762  
763 }
764  
765  
766 2 ▶sub __send_command {
Subroutine __send_command: called CC=13 SCAR=28.4
767 2 my $self = shift;
768 2 my $cmd = uc(shift);
769 2 my $deb = $self->{debug};
770  
771 # if already connected but after a fork, reconnect
772 2 ▶ if ($self->{sock} && ($self->{pid} || 0) != $$) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sock"} and ($self->{"pid"} || 0) != $$) 0 2 2
Condition40%2/5
$self->{"sock"} and ($self->{"pid"} || 0) != $$
!ll&&!rl&&r
020
$self->{'pid'} || 0
l!l
20
MC/DC0%0/2
$self->{"sock"} and ($self->{"pid"} || 0) != $$
$self->{"sock"} $self->{'pid'}
Truth table33%1/3
A and B
A= $self->{"sock"}B= $self->{'pid'}
ABresult
0X0
100
111
773 0 $self->connect;
774 }
775  
776 my $sock = $self->{sock}
777 2 ▶ || $self->__throw_reconnect('Not connected to any server');
Condition33%1/3
$self->{'sock'} || $self->__throw_reconnect('Not connected to any server')
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{'sock'} || $self->__throw_reconnect('Not connected to any server')
$self->{'sock'} $self->__throw_reconnect('Not connected to any server')
Truth table33%1/3
A || B
A= $self->{'sock'}B= $self->__throw_reconnect('Not connected to any server')
ABresult
1X1
011
000
778  
779 2 ▶ warn "[SEND] $cmd ", Dumper([@_]) if $deb;
Branch: 1 branch
BranchTrueFalseTotal
if $deb 0 2 2
780  
781 ## Encode command using multi-bulk format
782 2 my @cmd = split /_/, $cmd;
783 2 my $n_elems = scalar(@_) + scalar(@cmd);
784 2 my $buf = "\*$n_elems\r\n";
785 2 for my $bin (@cmd, @_) {
786 4 ▶ utf8::downgrade($bin, 1)
Branch: 1 branch
BranchTrueFalseTotal
utf8::downgrade($bin, 1) or croak("command sent is not an octet sequence in the native encoding (Latin-1). Consider using debug mode to see the command itself.") 4 0 4
787 or croak "command sent is not an octet sequence in the native encoding (Latin-1). Consider using debug mode to see the command itself.";
788 4 ▶ $buf .= defined($bin) ? '$' . length($bin) . "\r\n$bin\r\n" : "\$-1\r\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $bin ? : 4 0 4
789 }
790  
791 # this function works differently with a SSL socket cause it's not
792 # possible to read just a few bytes from a TLS frame.
793 2 my $status = $self->__try_read_sock($sock);
794 2 ▶ $self->__throw_reconnect('Not connected to any server')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 2 2
795 unless defined $status;
796  
797 ## Send command, take care for partial writes
798 2 ▶ warn "[SEND RAW] $buf" if $deb;
Branch: 1 branch
BranchTrueFalseTotal
if $deb 0 2 2
799 2 ▶ while ($buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf) 2 2 4
800 2 my $len = syswrite $sock, $buf, length $buf;
801 2 ▶ $self->__throw_reconnect("Could not write to Redis server: $!")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len 0 2 2
802 unless defined $len;
803 2 substr $buf, 0, $len, "";
804 }
805  
806 2 return;
807 }
808  
809 2 ▶sub __read_response {
Subroutine __read_response: called CC=3 SCAR=13.5
810 2 my ($self, $cmd, $collect_errors) = @_;
811  
812 2 ▶ croak("Not connected to any server") unless $self->{sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sock"} 0 2 2
813  
814 2 local $/ = "\r\n";
815  
816 ## no debug => fast path
817 2 ▶ return $self->__read_response_r($cmd, $collect_errors) unless $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug"} 2 0 2
818  
819 0 my ($result, $error) = $self->__read_response_r($cmd, $collect_errors);
820 0 warn "[RECV] $cmd ", Dumper($result, $error);
821 0 return $result, $error;
822 }
823  
824 2 ▶sub __read_response_r {
Subroutine __read_response_r: called CC=11 SCAR=43.4
825 2 my ($self, $command, $collect_errors) = @_;
826  
827 2 my ($type, $result) = $self->__read_line;
828  
829 1 ▶ if ($type eq '-') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq '-') { } 0 1 1
elsif ($type eq '+' or $type eq ':') { } 1 0 1
elsif ($type eq '$') { } 0 0 0
elsif ($type eq '*') { } 0 0 0
830 0 return undef, $result;
831 }
832 ▶ elsif ($type eq '+' || $type eq ':') {
Condition33%1/3
$type eq "+" or $type eq ":"
l!l&&r!l&&!r
100
MC/DC0%0/2
$type eq "+" or $type eq ":"
$type eq "+" $type eq ":"
Truth table33%1/3
A or B
A= $type eq "+"B= $type eq ":"
ABresult
1X1
011
000
833 1 return $result, undef;
834 }
835 elsif ($type eq '$') {
836 0 ▶ return undef, undef if $result < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $result < 0 0 0 0
837 0 return $self->__read_len($result + 2), undef;
838 }
839 elsif ($type eq '*') {
840 0 ▶ return undef, undef if $result < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $result < 0 0 0 0
841  
842 0 my @list;
843 0 ▶ while ($result--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result--) 0 0 0
844 0 my @nested = $self->__read_response_r($command, $collect_errors);
845 0 ▶ if ($collect_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($collect_errors) { } 0 0 0
846 0 push @list, \@nested;
847 }
848 else {
849 0 ▶ croak "[$command] $nested[1], " if defined $nested[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $nested[1] 0 0 0
850 0 push @list, $nested[0];
851 }
852 }
853 0 return \@list, undef;
854 }
855 else {
856 0 croak "unknown answer type: $type ($result), ";
857 }
858 }
859  
860 2 ▶sub __read_line {
Subroutine __read_line: called CC=3 SCAR=11.0
861 2 my $self = $_[0];
862 2 my $sock = $self->{sock};
863  
864 2 my $data = $self->__read_line_raw;
865 2 ▶ if (! defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 1 1 2
866 # In case the caller catches the exception and wants to persist on using
867 # the redis connection, let's forbid that.
868 1 $self->__close_sock();
869 1 croak("Error while reading from Redis server: $!")
870 }
871  
872 1 chomp $data;
873 1 ▶ warn "[RECV RAW] '$data'" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 1 1
874  
875 1 my $type = substr($data, 0, 1, '');
876 1 return ($type, $data);
877 }
878  
879 2 ▶sub __read_line_raw {
Subroutine __read_line_raw: called CC=8 SCAR=23.2
880 2 my $self = $_[0];
881 2 my $sock = $self->{sock};
882 2 my $buf = \$self->{__buf};
883  
884 2 ▶ if (length $$buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$buf) 0 2 2
885 0 my $idx = index($$buf, "\r\n");
886 0 ▶ $idx >= 0 and return substr($$buf, 0, $idx + 2, '');
Branch: 1 branch
BranchTrueFalseTotal
$idx >= 0 and return substr($$buf, 0, $idx + 2, "") 0 0 0
887 }
888  
889 2 while (1) {
890 2 my $bytes = sysread($sock, $$buf, BUFSIZE, length($$buf));
891 2 ▶ next if !defined $bytes && $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes and $! == 4 0 2 2
Condition66%2/3
not defined $bytes and $! == 4
!ll&&!rl&&r
110
MC/DC0%0/2
not defined $bytes and $! == 4
not defined $bytes $! == 4
Truth table66%2/3
not(A) and B
A= not defined $bytesB= $! == 4
ABresult
0X0
100
111
892 2 ▶ return unless defined $bytes && $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes and $bytes 1 1 2
Condition66%2/3
defined $bytes and $bytes
!ll&&!rl&&r
101
MC/DC50%1/2
defined $bytes and $bytes
defined $bytes $bytes
Truth table66%2/3
A and B
A= defined $bytesB= $bytes
ABresult
0X0
100
111
893  
894 # start looking for \r\n where we stopped last time
895 # extracting one is required to handle corner case
896 # where \r\n are split and therefore read by two conseqent sysreads
897 1 my $idx = index($$buf, "\r\n", length($$buf) - $bytes - 1);
898 1 ▶ $idx >= 0 and return substr($$buf, 0, $idx + 2, '');
Branch: 1 branch
BranchTrueFalseTotal
$idx >= 0 and return substr($$buf, 0, $idx + 2, "") 1 0 1
899 }
900 }
901  
902 0 ▶sub __read_len {
Subroutine __read_len: not called CC=8 SCAR=42.8
903 0 my ($self, $len) = @_;
904 0 my $buf = \$self->{__buf};
905 0 my $buflen = length($$buf);
906  
907 0 ▶ if ($buflen < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buflen < $len) 0 0 0
908 0 my $to_read = $len - $buflen;
909 0 ▶ while ($to_read > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_read > 0) 0 0 0
910 0 my $bytes = sysread($self->{sock}, $$buf, BUFSIZE, length($$buf));
911 0 ▶ next if !defined $bytes && $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $bytes and $! == 4 0 0 0
Condition0%0/3
not defined $bytes and $! == 4
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $bytes and $! == 4
not defined $bytes $! == 4
Truth table0%0/3
not(A) and B
A= not defined $bytesB= $! == 4
ABresult
0X0
100
111
912 0 ▶ croak("Error while reading from Redis server: $!") unless defined $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes 0 0 0
913 0 ▶ croak("Redis server closed connection") unless $bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes 0 0 0
914 0 $to_read -= $bytes;
915 }
916 }
917  
918 0 my $data = substr($$buf, 0, $len, '');
919 0 chomp $data;
920 0 ▶ warn "[RECV RAW] '$data'" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
921  
922 0 return $data;
923 }
924  
925 2 ▶sub __try_read_sock {
Subroutine __try_read_sock: called CC=14 SCAR=41.0
926 2 my ($self, $sock) = @_;
927 2 my $data = '';
928  
929 2 while (1) {
930 # WIN32 doesn't support MSG_DONTWAIT,
931 # need to swith fh to nonblockng mode manually.
932 # For Unix still use MSG_DONTWAIT because of fewer syscalls
933 2 my ($res, $err);
934 2 ▶ if (WIN32) {
Branch: 1 branch
BranchTrueFalseTotal
if (&WIN32()) { } 0 2 2
935 0 __fh_nonblocking_win32($sock, 1);
936 0 $res = recv($sock, $data, BUFSIZE, 0);
937 0 $err = 0 + $!;
938 0 __fh_nonblocking_win32($sock, 0);
939 } else {
940 2 ▶ if ($self->{ssl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ssl'}) { } 2 0 2
941 ## use peek to see if there is any data available instead of reading
942 ## it cause it's not possible to read only a few bytes from an SSL
943 ## frame. This does not work in WIN32
944 2 $sock->blocking(0);
945 2 $res = $sock->peek($data, BUFSIZE);
946 2 $sock->blocking(1);
947 } else {
948 0 $res = recv($sock, $data, BUFSIZE, MSG_DONTWAIT);
949 }
950  
951 2 $err = 0 + $!;
952 }
953  
954 2 ▶ if (defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res) 0 2 2
955 ## have read some data
956 0 ▶ if (length($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data) 0 0 0
957 0 ▶ $self->{__buf} .= $data unless $self->{ssl};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ssl"} 0 0 0
958 0 return 1;
959 }
960  
961 ## no data but also no error means EOF
962 0 return;
963 }
964  
965 2 ▶ next if $err && $err == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if $err and $err == 4 0 2 2
Condition33%1/3
$err and $err == 4
!ll&&!rl&&r
020
MC/DC0%0/2
$err and $err == 4
$err $err == 4
Truth table33%1/3
A and B
A= $errB= $err == 4
ABresult
0X0
100
111
966  
967 ## Keep going if nothing there, but socket is alive
968 2 ▶ return 0 if $err and ($err == EWOULDBLOCK or $err == EAGAIN);
Branch: 1 branch
BranchTrueFalseTotal
if $err and $err == 11 || $err == 11 2 0 2
Condition33%2/6
$err and $err == 11 || $err == 11
!ll&&!rl&&r
002
$err == 11 or $err == 11
l!l&&r!l&&!r
200
MC/DC0%0/3
$err and $err == 11 || $err == 11
$err $err == 11 $err == 11
Truth table25%1/4
A and B or C
A= $errB= $err == 11C= $err == 11
ABCresult
0XX0
1000
11X1
1011
969  
970 ## if we got ECONNRESET, it might be due a timeout from the other side (on freebsd)
971 ## or because an intermediate proxy shut down our connection using its internal timeout counter
972 0 ▶ return 0 if ($err && $err == ECONNRESET);
Branch: 1 branch
BranchTrueFalseTotal
if $err and $err == 104 0 0 0
Condition0%0/3
$err and $err == 104
!ll&&!rl&&r
000
MC/DC0%0/2
$err and $err == 104
$err $err == 104
Truth table0%0/3
A and B
A= $errB= $err == 104
ABresult
0X0
100
111
973  
974 ## result is undef but err is 0? should never happen
975 0 ▶ return if $err == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $err == 0 0 0 0
976  
977 ## For everything else, there is Mastercard...
978 0 croak("Unexpected error condition $err/$^O, please report this as a bug");
979 }
980 }
981  
982 ## Copied from AnyEvent::Util
983 0 ▶sub __fh_nonblocking_win32 {
Subroutine __fh_nonblocking_win32: not called CC=1 SCAR=6.9
984 0 ioctl $_[0], 0x8004667e, pack "L", $_[1];
985 }
986  
987 ##########################
988 # I take exception to that
989  
990 0 ▶sub __throw_reconnect {
Subroutine __throw_reconnect: not called CC=2 SCAR=17.9
991 0 my ($self, $m) = @_;
992 0 ▶ die bless(\$m, 'Redis::X::Reconnect') if $self->{reconnect};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"reconnect"} 0 0 0
993 0 die $m;
994 }
995  
996  
997 19 1; # End of Redis.pm
998  
999 __END__
↑ Summary Redis/Sentinel.pm »