Session/Redis.pm

filter: Statementstmt 56.2% 221 / 393 Branchbran 52.8% 94 / 178 Conditioncond 32.8% 23 / 70 MC/DCmcdc 19.0% 8 / 42 Subroutinesub 66.6% 34 / 51 Podpod 0.0% 0 / 11 totaltotal 51.0% 380 / 745 CC 140 SCAR 41.7
CC
140
Cov
53%
__ANON__
306.0
searchOn
272.0
__ANON__
132.0
CRAP 64.5
« Session/MySQLJSON.pm ↑ Summary Session/LDAP.pm »
1 package Web::Session::Redis;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 ▶use Apache::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Web::Session::Store::Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Web::Session::Generate::SHA256;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Apache::Session::Lock::Null;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Web::Session::Serialize::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Web::Session::_common;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 our $VERSION = '1.2.0';
13 10 our @ISA = qw(Apache::Session);
14  
15 0 ▶sub populate {
Subroutine populate: not called CC=1 SCAR=6.9
Pod undocumented
16 0 my $self = shift;
17  
18 0 $self->{object_store} = new Web::Session::Store::Redis $self;
19 0 $self->{lock_manager} = new Apache::Session::Lock::Null $self;
20 0 $self->{generate} = \&Web::Session::Generate::SHA256::generate;
21 0 $self->{validate} = \&Web::Session::Generate::SHA256::validate;
22 0 $self->{serialize} = \&Web::Session::Serialize::JSON::serializeLatin1;
23 0 $self->{unserialize} = \&_unserializeRead;
24  
25 0 return $self;
26 }
27  
28 # Keeps the version read for the store's update(). Lemonldap::NG's local cache
29 # may provide it instead of materialize(), but unserialize is always called
30 3 ▶sub _unserializeRead {
Subroutine _unserializeRead: called CC=1 SCAR=0.0
31 3 my ($session) = @_;
32 3 $session->{ +Web::Session::Store::Redis::READ } = $session->{serialized};
33 3 return Web::Session::Serialize::JSON::unserializeLatin1(@_);
34 }
35  
36 # Key name sent to Redis, see Store::Redis::keyName()
37 16 ▶sub _keyName {
Subroutine _keyName: called CC=1 SCAR=0.0
38 16 return Web::Session::Store::Redis::keyName(@_);
39 }
40  
41 # Index sets, plus index hashes with utimeOffset: [ name, is a hash ]. The
42 # prefix is ASCII, so the name of a hash keeps the Latin-1 or UTF-8 encoding
43 # of the name of the set
44 12 ▶sub _indexNames {
Subroutine _indexNames: called CC=2 SCAR=7.2
45 12 my ( $args, $name ) = @_;
46 return (
47 12 ▶ [ $name, 0 ],
Branch: 1 branch
BranchTrueFalseTotal
Web::Session::Store::Redis::hashIndex($args) ? : 0 12 12
48 (
49 Web::Session::Store::Redis::hashIndex($args)
50 ? [ $Web::Session::Store::Redis::HASH_INDEX_PREFIX . $name, 1 ]
51 : ()
52 )
53 );
54 }
55  
56 # SCAN patterns for searchOnExpr(). The name of a set is Latin-1 unless it
57 # holds characters above U+00FF, so a wildcard may stand for such characters
58 # while the literal part is not ASCII: the UTF-8 form is then scanned too
59 4 ▶sub _exprPatterns {
Subroutine _exprPatterns: called CC=3 SCAR=11.0
60 4 my ( $field, $value ) = @_;
61 4 my $pattern = _exprPattern( $field, $value );
62 4 my @res = ( _keyName($pattern) );
63 4 ▶ if ( $value =~ /\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\*/) 3 1 4
64 3 my $p = $pattern;
65 3 utf8::encode($p);
66 3 ▶ push @res, $p unless ( $p eq $res[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless $p eq $res[0] 1 2 3
67 }
68 4 return @res;
69 }
70  
71 33 ▶sub unserialize {
Subroutine unserialize: called CC=1 SCAR=0.0
Pod undocumented
72 33 my $session = shift;
73 33 my $tmp = { serialized => $session };
74 33 Web::Session::Serialize::JSON::unserializeLatin1($tmp);
75 33 return $tmp->{data};
76 }
77  
78 # Keys per SCAN call (a hint for Redis)
79 10 our $SCAN_COUNT = 1000;
80  
81 # Keys per MGET: a huge index set must not block Redis with one big command
82 10 our $MGET_BATCH = 500;
83  
84 # Like $redisObj->mget(@keys), in batches. MGET returns undef for missing
85 # keys and keys that aren't strings
86 16 ▶sub _mget {
Subroutine _mget: called CC=2 SCAR=6.9
87 16 my ( $redisObj, @keys ) = @_;
88 16 my @res;
89 16 ▶ while (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 18 16 34
90 18 push @res, $redisObj->mget( splice( @keys, 0, $MGET_BATCH ) );
91 }
92 16 return @res;
93 }
94  
95 # Members of index sets @$sets (index hashes if $hash), read in one pipeline:
96 # { set => [ keys ] }. A key of another type is ignored; other Redis errors
97 # are raised
98 2 ▶sub _smembers {
Subroutine _smembers: called CC=1 SCAR=0.0
99 2 my ( $redisObj, $sets, $hash ) = @_;
100 2 return _indexMembers( $redisObj, [ map { [ $_, $hash ] } @$sets ] );
101 }
102  
103 # Same as _smembers() for index sets and hashes @$names: [ name, is a hash ]
104 2 ▶sub _indexMembers {
Subroutine _indexMembers: called CC=4 SCAR=13.9
105 2 my ( $redisObj, $names ) = @_;
106 2 my ( %res, $fatal );
107 2 foreach my $name (@$names) {
108 5 my ( $set, $hash ) = @$name;
109 5 ▶ my $cmd = $hash ? 'hkeys' : 'smembers';
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 0 5 5
110 $redisObj->$cmd(
111 $set,
112 5 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
113 5 my ( $reply, $err ) = @_;
114 5 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) { } 3 2 5
115 3 ▶ $fatal //= $err unless ( $err =~ /WRONGTYPE/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /WRONGTYPE/ 2 1 3
Condition66%2/3
$fatal //= $err
l!l&&r!l&&!r
110
MC/DC0%0/2
$fatal //= $err
$fatal $err
Truth table66%2/3
A //= B
A= $fatalB= $err
ABresult
1X1
011
000
116 }
117 else {
118 2 $res{$set} = $reply;
119 }
120 }
121 5 );
122 }
123 2 $redisObj->wait_all_responses;
124 2 ▶ die $fatal if ($fatal);
Branch: 1 branch
BranchTrueFalseTotal
if $fatal 1 1 2
125 1 return \%res;
126 }
127  
128 # Remove session KEYS[2] from index KEYS[1] only if it doesn't exist, in one
129 # step: a concurrent writer may be recreating it
130 10 our $SREM_ORPHAN = q{if redis.call('exists',KEYS[2])==0 then }
131 . q{return redis.call('srem',KEYS[1],KEYS[2]) end return 0};
132 10 our $HDEL_ORPHAN = q{if redis.call('exists',KEYS[2])==0 then }
133 . q{return redis.call('hdel',KEYS[1],KEYS[2]) end return 0};
134  
135 10 our $lua_warned;
136  
137 # Remove orphan session $k from index set $set (index hash if $hash). Without
138 # Lua (EVAL forbidden by ACL, proxy...), WATCH the session so that a
139 # concurrent writer aborts the removal. $k must have been checked with
140 # isLlngKey()
141 5 ▶sub _removeOrphan {
Subroutine _removeOrphan: called CC=7 SCAR=20.1
142 5 my ( $class, $redisObj, $set, $k, $hash ) = @_;
143 return
144 if (
145 5 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { $redisObj->eval($hash ? $Web::Session::Redis::HDEL_ORPHAN : $Web::Session::Redis::SREM_ORPHAN, 2, $set, $k); 1 } } 2 3 5
146 5 ▶ $redisObj->eval( ( $hash ? $HDEL_ORPHAN : $SREM_ORPHAN ),
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 2 3 5
147 2, $set, $k );
148 2 1;
149 }
150 );
151 3 ▶ unless ($lua_warned) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Web::Session::Redis::lua_warned) 1 2 3
152 1 $lua_warned = 1;
153 1 print STDERR "Redis EVAL failed, orphan index members are removed "
154 . "without Lua: $@\n";
155 }
156 3 my $err;
157 3 eval {
158 3 $redisObj->watch($k);
159 3 ▶ if ( $redisObj->exists($k) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redisObj->exists($k)) { } 1 2 3
160 1 $redisObj->unwatch;
161 }
162 else {
163 2 $redisObj->multi;
164 2 ▶ $hash ? $redisObj->hdel( $set, $k ) : $redisObj->srem( $set, $k );
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 1 1 2
165 2 $redisObj->exec;
166 }
167 };
168 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
169 0 $err = $@;
170 0 eval { $redisObj->discard };
171 0 eval { $redisObj->unwatch };
172 0 print STDERR "Unable to remove '$k' from index $set: $err\n";
173 }
174 }
175  
176 0 ▶sub searchOn {
Subroutine searchOn: not called CC=16 SCAR=56.1
Pod undocumented
177 0 my ( $class, $args, $selectField, $value, @fields ) = @_;
178  
179 0 my %res = ();
180 0 ▶ if ( $class->isIndexed( $args, $selectField ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isIndexed($args, $selectField)) { } 0 0 0
181  
182 0 my $redisObj = $class->_getRedis($args);
183 0 my ( @keys, %index, %seen );
184 0 my @names = _indexNames( $args, _keyName("${selectField}_$value") );
185 0 my $members = _indexMembers( $redisObj, \@names );
186 0 foreach my $name (@names) {
187  
188 # Members of another application are neither read nor removed
189 0 ▶ foreach ( @{ $members->{ $name->[0] } || [] } ) {
Condition0%0/2
$$members{$name->[0]} || []
l!l
00
MC/DC0%0/1
$$members{$name->[0]} || []
$$members{$name->[0]}
Truth table0%0/2
A
A= $$members{$name->[0]}
Aresult
11
00
190 0 ▶ next unless ( $_ and $class->isLlngKey( $args, $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $_ and $class->isLlngKey($args, $_) 0 0 0
Condition0%0/3
$_ and $class->isLlngKey($args, $_)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ and $class->isLlngKey($args, $_)
$_ $class->isLlngKey($args, $_)
Truth table0%0/3
A and B
A= $_B= $class->isLlngKey($args, $_)
ABresult
0X0
100
111
191 0 push @{ $index{$_} }, $name;
192 0 ▶ push @keys, $_ unless ( $seen{$_}++ );
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$_}++ 0 0 0
193 }
194 }
195 0 my %values;
196 0 @values{@keys} = _mget( $redisObj, @keys );
197 0 foreach my $k (@keys) {
198 0 my $tmp = $values{$k};
199 0 ▶ unless ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp) 0 0 0
200 # Lazy cleanup: remove orphan from index
201 $class->_removeOrphan( $redisObj, $_->[0], $k, $_->[1] )
202 0 foreach ( @{ $index{$k} } );
203 0 next;
204 }
205 0 eval {
206 0 $tmp = unserialize($tmp);
207  
208 # The index may be stale or shared with another field
209 # ("a_b" + "c" and "a" + "b_c" give the same set name)
210 return
211 unless ( defined $tmp->{$selectField}
212 0 ▶ and $tmp->{$selectField} eq $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tmp->{$selectField} and $tmp->{$selectField} eq $value 0 0 0
Condition0%0/3
defined $tmp->{$selectField} and $tmp->{$selectField} eq $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tmp->{$selectField} and $tmp->{$selectField} eq $value
defined $tmp->{$selectField} $tmp->{$selectField} eq $value
Truth table0%0/3
A and B
A= defined $tmp->{$selectField}B= $tmp->{$selectField} eq $value
ABresult
0X0
100
111
213 0 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 0 0 0
214 0 $res{$k}->{$_} = $tmp->{$_} foreach (@fields);
215 }
216 else {
217 0 $res{$k} = $tmp;
218 }
219 };
220 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
221 0 print STDERR "Error in session $k: $@\n";
222 0 delete $res{$k};
223 }
224 }
225 }
226 else {
227 $class->get_key_from_all_sessions(
228 $args,
229 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
230 0 my $entry = shift;
231 0 my $id = shift;
232 return undef
233 unless ( defined $entry->{$selectField}
234 0 ▶ and $entry->{$selectField} eq $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry->{$selectField} and $entry->{$selectField} eq $value 0 0 0
Condition0%0/3
defined $entry->{$selectField} and $entry->{$selectField} eq $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entry->{$selectField} and $entry->{$selectField} eq $value
defined $entry->{$selectField} $entry->{$selectField} eq $value
Truth table0%0/3
A and B
A= defined $entry->{$selectField}B= $entry->{$selectField} eq $value
ABresult
0X0
100
111
235 0 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 0 0 0
236 0 $res{$id}->{$_} = $entry->{$_} foreach (@fields);
237 }
238 else {
239 0 $res{$id} = $entry;
240 }
241 0 undef;
242 }
243 0 );
244 }
245 0 return \%res;
246 }
247  
248 # Regexp of the names matched by the SCAN pattern $glob: '*' is its only
249 # wildcard, a backslash escapes the next character
250 9 ▶sub _globRe {
Subroutine _globRe: called CC=2 SCAR=6.9
251 9 my ($glob) = @_;
252 my $re = join '',
253 9 ▶ map { $_ eq '*' ? '.*' : quotemeta( substr( $_, -1 ) ) }
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '*' ? : 9 51 60
254 $glob =~ /(\\.|.)/gs;
255 9 return qr/^$re\z/s;
256 }
257  
258 # Call $cb->( \@sets, $hash ) for each SCAN page of the index sets matching
259 # $pattern and, with utimeOffset, of the index hashes: "*$pattern" matches
260 # both, so that the keyspace is walked once. @opts are given to SCAN
261 2 ▶sub _scanIndexes {
Subroutine _scanIndexes: called CC=5 SCAR=16.1
262 2 my ( $redisObj, $args, $pattern, $cb, @opts ) = @_;
263 2 my $hash = Web::Session::Store::Redis::hashIndex($args);
264 2 my ( $setRe, $hashRe );
265 2 ▶ if ($hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) 1 1 2
266 1 $setRe = _globRe($pattern);
267 1 $hashRe = _globRe(
268 _globEscape($Web::Session::Store::Redis::HASH_INDEX_PREFIX)
269 . $pattern );
270 }
271 2 my $cursor = 0;
272 2 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$cursor != 0 and do { do { () = $redisObj->scan($cursor, "MATCH", $hash ? "*$pattern" : $pattern, @opts); if ($hash) { &$cb([grep({$_ =~ /$setRe/;} @$keys)], 0); &$cb([grep({$_ =~ /$hashRe/;} @$keys)], 1); } else { &$cb($keys, 0); } ; $cursor = $new_cursor } } 2 2 4
273 4 ▶ my ( $new_cursor, $keys ) = $redisObj->scan( $cursor,
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 2 2 4
274 MATCH => ( $hash ? "*$pattern" : $pattern ),
275 @opts );
276 4 ▶ if ($hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash) { } 2 2 4
277 2 $cb->( [ grep { $_ =~ $setRe } @$keys ], 0 );
278 2 $cb->( [ grep { $_ =~ $hashRe } @$keys ], 1 );
279 }
280 else {
281 2 $cb->( $keys, 0 );
282 }
283 4 $cursor = $new_cursor;
284 } while ( $cursor != 0 );
285 }
286  
287 # searchOnExpr() patterns: '*' is a wildcard
288 0 ▶sub _exprRe {
Subroutine _exprRe: not called CC=1 SCAR=6.9
289 0 my ($value) = @_;
290 0 $value = quotemeta($value);
291 0 $value =~ s/\\\*/\.\*/g;
292 0 return qr/^$value$/;
293 }
294  
295 # Redis glob escape: MATCH patterns of SCAN must find names literally
296 11 ▶sub _globEscape {
Subroutine _globEscape: called CC=1 SCAR=0.0
297 11 my ($s) = @_;
298 11 $s =~ s/([*?\[\]\\])/\\$1/g;
299 11 return $s;
300 }
301  
302 # SCAN pattern of the index sets for searchOnExpr(): '*' is the only
303 # wildcard of the value. The sessions are checked afterwards with _exprRe()
304 9 ▶sub _exprPattern {
Subroutine _exprPattern: called CC=1 SCAR=0.0
305 9 my ( $field, $value ) = @_;
306 9 $value =~ s/([?\[\]\\])/\\$1/g;
307 9 return _globEscape($field) . "_$value";
308 }
309  
310 0 ▶sub searchOnExpr {
Subroutine searchOnExpr: not called CC=3 SCAR=24.8
Pod undocumented
311 0 my ( $class, $args, $selectField, $value, @fields ) = @_;
312 0 my %res;
313 0 my $re = _exprRe($value);
314 0 ▶ if ( $class->isIndexed( $args, $selectField ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isIndexed($args, $selectField)) { } 0 0 0
315 0 my $redisObj = $class->_getRedis($args);
316 0 foreach my $pattern ( _exprPatterns( $selectField, $value ) ) {
317 _scanIndexes(
318 $redisObj, $args, $pattern,
319 0 ▶ sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
320 0 my ( $sets, $hash ) = @_;
321  
322 # The sets of a SCAN page are read together: a few round
323 # trips instead of two per set. Members of another
324 # application are neither read nor removed
325 0 my $members = _smembers( $redisObj, $sets, $hash );
326 0 foreach my $set ( keys %$members ) {
327 $members->{$set} =
328 0 ▶ [ grep { $_ and $class->isLlngKey( $args, $_ ) }
Condition0%0/3
$_ && $class->isLlngKey($args, $_)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && $class->isLlngKey($args, $_)
$_ $class->isLlngKey($args, $_)
Truth table0%0/3
A && B
A= $_B= $class->isLlngKey($args, $_)
ABresult
0X0
100
111
329 0 @{ $members->{$set} } ];
330 }
331 0 my %seen;
332 my @keys =
333 0 grep { !$seen{$_}++ } map { @$_ } values %$members;
334 0 my %values;
335 0 @values{@keys} = _mget( $redisObj, @keys );
336 0 foreach my $set ( keys %$members ) {
337 0 foreach my $k ( @{ $members->{$set} } ) {
338 0 my $v = $values{$k};
339 0 ▶ unless ($v) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v) 0 0 0
340 # Lazy cleanup: remove orphan from index
341 0 $class->_removeOrphan( $redisObj, $set, $k,
342 $hash );
343 0 next;
344 }
345 0 my $tmp = eval { unserialize($v) };
346 0 ▶ if ( $@ or ref($tmp) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or ref $tmp ne "HASH") 0 0 0
Condition0%0/3
$@ or ref $tmp ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or ref $tmp ne "HASH"
$@ ref $tmp ne "HASH"
Truth table0%0/3
A or B
A= $@B= ref $tmp ne "HASH"
ABresult
1X1
011
000
347 0 ▶ print STDERR "Error in session $k: "
Condition0%0/2
$@ || "not a session\n"
l!l
00
MC/DC0%0/1
$@ || "not a session\n"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
348 . ( $@ || "not a session\n" );
349 0 next;
350 }
351  
352 # The pattern may match sets of another field
353 0 ▶ unless ( defined $tmp->{$selectField}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp->{$selectField} and $tmp->{$selectField} =~ /$re/) 0 0 0
Condition0%0/3
defined $tmp->{$selectField} and $tmp->{$selectField} =~ /$re/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tmp->{$selectField} and $tmp->{$selectField} =~ /$re/
defined $tmp->{$selectField} $tmp->{$selectField} =~ /$re/
Truth table0%0/3
A and B
A= defined $tmp->{$selectField}B= $tmp->{$selectField} =~ /$re/
ABresult
0X0
100
111
354 and $tmp->{$selectField} =~ $re )
355 {
356 0 next;
357 }
358 0 $res{$k} =
359 $class->extractFields( $tmp, @fields );
360 }
361 }
362 },
363 0 COUNT => $SCAN_COUNT
364 );
365 }
366 }
367 else {
368 $class->get_key_from_all_sessions(
369 $args,
370 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
371 0 my ( $entry, $id ) = @_;
372 0 ▶ return undef unless ( $entry->{$selectField} =~ $re );
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{$selectField} =~ /$re/ 0 0 0
373 0 $res{$id} = $class->extractFields( $entry, @fields );
374 0 undef;
375 }
376 0 );
377 }
378 0 return \%res;
379 }
380  
381 0 ▶sub searchLt {
Subroutine searchLt: not called CC=1 SCAR=6.9
Pod undocumented
382 0 my $class = shift;
383 0 return $class->_searchCompare( '<', @_ );
384 }
385  
386 0 ▶sub searchGt {
Subroutine searchGt: not called CC=1 SCAR=6.9
Pod undocumented
387 0 my $class = shift;
388 0 return $class->_searchCompare( '>', @_ );
389 }
390  
391 # Trimmed number, or undef
392 0 ▶sub _number {
Subroutine _number: not called CC=4 SCAR=30.0
393 0 my ($v) = @_;
394 0 ▶ return undef unless ( defined($v) and !ref($v) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v and not ref $v 0 0 0
Condition0%0/3
defined $v and not ref $v
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not ref $v
defined $v not ref $v
Truth table0%0/3
A and not(B)
A= defined $vB= not ref $v
ABresult
0X0
100
111
395 0 $v =~ s/^\s+|\s+$//g;
396 0 ▶ return $v =~ /^-?[0-9]+(?:\.[0-9]+)?\z/ ? $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /^-?[0-9]+(?:\.[0-9]+)?\z/ ? : 0 0 0
397 }
398  
399 # Sessions where $selectField isn't a number (see _number()) are skipped.
400 # Indexed field: SCAN walks the keyspace server-side and returns only the
401 # index sets of $selectField; only sets holding a matching value are read.
402 # Used by purges: Redis errors are reported and the sets ignored
403 0 ▶sub _searchCompare {
Subroutine _searchCompare: not called CC=4 SCAR=30.0
404 0 my ( $class, $op, $args, $selectField, $value, @fields ) = @_;
405  
406 # LLNG CLI keeps spaces around the value ("--where 'f < 123 '")
407 0 $value = _number($value);
408 0 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
409 0 ▶ print STDERR 'search'
Branch: 1 branch
BranchTrueFalseTotal
$op eq '<' ? : 0 0 0
410 . ( $op eq '<' ? 'Lt' : 'Gt' )
411 . ": value must be a number\n";
412 0 return {};
413 }
414 0 ▶ my $test = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
415 0 my $v = _number(shift);
416 0 ▶ return 0 unless ( defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
417 0 ▶ return $op eq '<' ? $v < $value : $v > $value;
Branch: 1 branch
BranchTrueFalseTotal
$op eq '<' ? : 0 0 0
418 0 };
419 0 my %res;
420 0 ▶ unless ( $class->isIndexed( $args, $selectField ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isIndexed($args, $selectField)) 0 0 0
421 $class->get_key_from_all_sessions(
422 $args,
423 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
424 0 my ( $entry, $id ) = @_;
425 $res{$id} = $class->extractFields( $entry, @fields )
426 0 ▶ if ( $test->( $entry->{$selectField} ) );
Branch: 1 branch
BranchTrueFalseTotal
if &$test($entry->{$selectField}) 0 0 0
427 0 undef;
428 }
429 0 );
430 0 return \%res;
431 }
432  
433 0 my $redisObj = $class->_getRedis($args);
434 0 my $prefix = "${selectField}_";
435 0 ( my $pattern = $prefix ) =~ s/([*?\[\]\\])/\\$1/g;
436 _scanIndexes(
437 $redisObj, $args,
438 "$pattern*",
439 0 ▶ sub {
Subroutine __ANON__: not called CC=17 SCAR=57.2
440 0 my ( $sets, $hash ) = @_;
441 0 ▶ my $cmd = $hash ? 'hkeys' : 'smembers';
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 0 0 0
442 0 ▶ my $skip = length($prefix) + (
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 0 0 0
443 $hash
444 ? length($Web::Session::Store::Redis::HASH_INDEX_PREFIX)
445 : 0
446 );
447  
448 # Sets of other fields ("${selectField}_x_1") aren't numbers
449 0 foreach my $set ( grep { $test->( substr( $_, $skip ) ) } @$sets )
450 {
451 0 my @keys = eval { $redisObj->$cmd($set) };
452 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
453 0 ▶ print STDERR "Error when reading index $set: $@\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $@ =~ /WRONGTYPE/ 0 0 0
454 unless ( $@ =~ /WRONGTYPE/ );
455 0 next;
456 }
457 0 foreach my $k (@keys) {
458  
459 # Members of another application are neither read nor
460 # removed
461 next
462 unless ( $k
463 0 ▶ and !exists $res{$k}
Branch: 1 branch
BranchTrueFalseTotal
unless $k and not exists $res{$k} and $class->isLlngKey($args, $k) 0 0 0
Condition0%0/6
$k and not exists $res{$k} and $class->isLlngKey($args, $k)
!ll&&!rl&&r
000
$k and not exists $res{$k}
!ll&&!rl&&r
000
MC/DC0%0/3
$k and not exists $res{$k} and $class->isLlngKey($args, $k)
$k not exists $res{$k} $class->isLlngKey($args, $k)
Truth table0%0/4
A and not(B) and C
A= $kB= not exists $res{$k}C= $class->isLlngKey($args, $k)
ABCresult
0XX0
10X0
1100
1111
464 and $class->isLlngKey( $args, $k ) );
465 0 my $v = eval { $redisObj->get($k) };
466 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
467 0 ▶ print STDERR "Error when reading $k: $@\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $@ =~ /WRONGTYPE/ 0 0 0
468 unless ( $@ =~ /WRONGTYPE/ );
469 0 next;
470 }
471 0 ▶ unless ($v) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v) 0 0 0
472  
473 # Lazy cleanup: remove orphan from index
474 0 $class->_removeOrphan( $redisObj, $set, $k, $hash );
475 0 next;
476 }
477 0 my $tmp = eval { unserialize($v) };
478 0 ▶ if ( $@ or ref($tmp) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or ref $tmp ne "HASH") 0 0 0
Condition0%0/3
$@ or ref $tmp ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or ref $tmp ne "HASH"
$@ ref $tmp ne "HASH"
Truth table0%0/3
A or B
A= $@B= ref $tmp ne "HASH"
ABresult
1X1
011
000
479 0 ▶ print STDERR "Error in session $k: "
Condition0%0/2
$@ || "not a session\n"
l!l
00
MC/DC0%0/1
$@ || "not a session\n"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
480 . ( $@ || "not a session\n" );
481 0 next;
482 }
483  
484 # The index may be stale: check the session itself
485 $res{$k} = $class->extractFields( $tmp, @fields )
486 0 ▶ if ( $test->( $tmp->{$selectField} ) );
Branch: 1 branch
BranchTrueFalseTotal
if &$test($tmp->{$selectField}) 0 0 0
487 }
488 }
489 }
490 0 );
491 0 return \%res;
492 }
493  
494 # Decide if a session must be purged. Like Lemonldap::NG's generic purge,
495 # only a missing _utime means "expired": any other missing field is not lower
496 # than the threshold (so a session without _lastSeen is not purged by it).
497 31 ▶sub _isDominated {
Subroutine _isDominated: called CC=14 SCAR=26.4
498 31 my ( $class, $v, $rule ) = @_;
499  
500 # Empty or data-less sessions should be purged
501 31 ▶ return 1 if ( !$v || !%$v || !exists $v->{_session_id} );
Branch: 1 branch
BranchTrueFalseTotal
unless $v and %$v and exists $v->{"_session_id"} 3 28 31
Condition100%6/6
$v and %$v and exists $v->{"_session_id"}
!ll&&!rl&&r
2128
$v and %$v
!ll&&!rl&&r
1129
MC/DC100%3/3
$v and %$v and exists $v->{"_session_id"}
$v %$v exists $v->{"_session_id"}
Truth table100%4/4
A and B and C
A= $vB= %$vC= exists $v->{"_session_id"}
ABCresult
0XX0
10X0
1100
1111
502 28 ▶ if ( $rule->{or} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rule->{'or'}) { } 23 5 28
elsif ($rule->{'and'}) { } 4 1 5
503 23 foreach ( keys %{ $rule->{or} } ) {
504 27 ▶ if ( !defined( $v->{$_} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v->{$_}) 3 24 27
505  
506 # Session without _utime: treat as expired
507 3 ▶ return 1 if $_ eq '_utime';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "_utime" 1 2 3
508 2 next;
509 }
510 24 ▶ return 1 if $v->{$_} < $rule->{or}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{$_} < $rule->{"or"}{$_} 14 10 24
511 }
512 }
513 elsif ( $rule->{and} ) {
514 4 foreach ( keys %{ $rule->{and} } ) {
515 8 ▶ if ( !defined( $v->{$_} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v->{$_}) 2 6 8
516  
517 # Only a missing _utime counts as lower
518 2 ▶ return 0 unless $_ eq '_utime';
Branch: 1 branch
BranchTrueFalseTotal
unless $_ eq "_utime" 1 1 2
519 1 next;
520 }
521 6 ▶ return 0 unless $v->{$_} < $rule->{and}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $v->{$_} < $rule->{"and"}{$_} 1 5 6
522 }
523 2 return 1;
524 }
525 9 return 0;
526 }
527  
528 15 ▶sub deleteIfLowerThan {
Subroutine deleteIfLowerThan: called CC=7 SCAR=19.8
Pod undocumented
529 15 my ( $class, $args, $rule ) = @_;
530  
531 # Same contract as the SQL backends: an invalid rule deletes nothing
532 15 ▶ return wantarray ? ( 0, 0 ) : 0
Branch: 2 branches
BranchTrueFalseTotal
unless "Web::Session::_common"->_checkRule($rule) and "Web::Session::_common"->_checkThresholds($rule) 8 7 15
wantarray ? : 4 4 8
Condition100%3/3
"Web::Session::_common"->_checkRule($rule) and "Web::Session::_common"->_checkThresholds($rule)
!ll&&!rl&&r
627
MC/DC100%2/2
"Web::Session::_common"->_checkRule($rule) and "Web::Session::_common"->_checkThresholds($rule)
"Web::Session::_common"->_checkRule($rule) "Web::Session::_common"->_checkThresholds($rule)
Truth table100%3/3
A and B
A= "Web::Session::_common"->_checkRule($rule)B= "Web::Session::_common"->_checkThresholds($rule)
ABresult
0X0
100
111
533 unless ( Web::Session::_common->_checkRule($rule)
534 and Web::Session::_common->_checkThresholds($rule) );
535 7 my $deleted = 0;
536 7 my $redisObj = $class->_getRedis($args);
537 my $index =
538 ref( $args->{Index} )
539 ? $args->{Index}
540 7 ▶ : [ split /\s+/, $args->{Index} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{'Index'} ? : 0 7 7
541  
542 7 my $ok = eval {
543 $class->_scanSessions(
544 $args,
545 11 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=23.5
546 11 my @expired;
547 11 foreach ( @{ $_[0] } ) {
548 25 my ( $k, $raw ) = @$_;
549 25 my $v = eval { unserialize($raw) };
550 25 ▶ unless ( ref($v) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $v eq "HASH") 0 25 25
551 0 ▶ print STDERR "Error in session $k: "
Condition0%0/2
$@ || "not a session\n"
l!l
00
MC/DC0%0/1
$@ || "not a session\n"
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
552 . ( $@ || "not a session\n" );
553 0 next;
554 }
555 next
556 if (
557 $rule->{not}
558 and grep {
559 defined( $v->{$_} )
560 25 ▶ and $v->{$_} eq $rule->{not}->{$_}
Condition66%2/3
defined $v->{$_} && $v->{$_} eq $rule->{'not'}{$_}
!ll&&!rl&&r
1807
MC/DC50%1/2
defined $v->{$_} && $v->{$_} eq $rule->{'not'}{$_}
defined $v->{$_} $v->{$_} eq $rule->{'not'}{$_}
Truth table66%2/3
A && B
A= defined $v->{$_}B= $v->{$_} eq $rule->{'not'}{$_}
ABresult
0X0
100
111
561 25 ▶ } keys %{ $rule->{not} }
Branch: 1 branch
BranchTrueFalseTotal
if $rule->{"not"} and grep {defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_};} keys %{$$rule{"not"};} 7 18 25
Condition66%2/3
$rule->{"not"} and grep {defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_};} keys %{$$rule{"not"};}
!ll&&!rl&&r
0187
MC/DC50%1/2
$rule->{"not"} and grep {defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_};} keys %{$$rule{"not"};}
$rule->{"not"} grep {defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_};} keys %{$$rule{"not"};}
Truth table66%2/3
A and B
A= $rule->{"not"}B= grep {defined $v->{$_} and $v->{$_} eq $rule->{"not"}{$_};} keys %{$$rule{"not"};}
ABresult
0X0
100
111
562 );
563 18 ▶ push @expired, [ $k, $v ]
Branch: 1 branch
BranchTrueFalseTotal
if $class->_isDominated($v, $rule) 12 6 18
564 if ( $class->_isDominated( $v, $rule ) );
565 }
566 11 ▶ _deleteSessions( $redisObj, $args, $index, \@expired,
Branch: 1 branch
BranchTrueFalseTotal
if @expired 11 0 11
567 \$deleted )
568 if (@expired);
569 },
570 7 $redisObj
571 );
572 2 1;
573 };
574 7 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 5 2 7
575 5 print STDERR "Redis error while purging sessions: $@";
576 5 ▶ return wantarray ? ( 0, $deleted ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 1 5
577 }
578 2 return ( 1, $deleted );
579 }
580  
581 # Deletes the sessions [ $key, $data ] of @$expired and their index entries,
582 # in two round trips: the index entries first, then the sessions whose
583 # entries were all removed (a session whose entry can't be removed is kept,
584 # so that no index entry points to a deleted session). Adds the sessions
585 # deleted to $$deleted, also those answered before a failure. Dies when the
586 # server fails (connection lost, read-only replica after a failover): an
587 # index entry refused by it is not a reason to keep the session and go on.
588 # If the DEL round trip fails, the sessions whose index entries were removed
589 # stay, missing from the indexes until a purge deletes them
590 11 ▶sub _deleteSessions {
Subroutine _deleteSessions: called CC=5 SCAR=16.2
591 11 my ( $redisObj, $args, $index, $expired, $deleted ) = @_;
592 11 my ( %failed, $fatal );
593 _pipelined(
594 $redisObj,
595 11 ▶ sub {
Subroutine __ANON__: called CC=7 SCAR=19.8
596 11 foreach (@$expired) {
597 12 my ( $k, $v ) = @$_;
598 12 foreach my $i (@$index) {
599 12 my $t = $v->{$i};
600 12 ▶ next unless ( defined($t) and length($t) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t and length $t > 0 0 12 12
Condition33%1/3
defined $t and length $t > 0
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $t and length $t > 0
defined $t length $t > 0
Truth table33%1/3
A and B
A= defined $tB= length $t > 0
ABresult
0X0
100
111
601 12 foreach ( _indexNames( $args, _keyName("${i}_$t") ) ) {
602 12 my ( $name, $hash ) = @$_;
603 10 ▶ my $cb = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
604 10 ▶ return unless ( defined $_[1] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 8 2 10
605 2 ▶ if ( $_[1] =~
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ /$Web::Session::Store::Redis::CONNECTION_ERROR/) 1 1 2
606 $Web::Session::Store::Redis::CONNECTION_ERROR )
607 {
608 1 ▶ $fatal //= "$_[1]\n";
Condition50%1/2
$fatal //= "$_[1]\n"
l!l
01
MC/DC0%0/1
$fatal //= "$_[1]\n"
$fatal
Truth table50%1/2
A
A= $fatal
Aresult
11
00
609 1 return;
610 }
611 1 warn "Failed to remove '$k' from index '$name': "
612 . "$_[1]\n";
613 1 $failed{$k} = 1;
614 12 };
615 12 ▶ $hash
Branch: 1 branch
BranchTrueFalseTotal
$hash ? : 0 12 12
616 ? $redisObj->hdel( $name, $k, $cb )
617 : $redisObj->srem( $name, $k, $cb );
618 }
619 }
620 }
621 }
622 11 );
623 9 ▶ die $fatal if ( defined $fatal );
Branch: 1 branch
BranchTrueFalseTotal
if defined $fatal 1 8 9
624 8 my @keys = grep { !$failed{$_} } map { $_->[0] } @$expired;
625 warn "Skipping deletion of session '$_' due to index cleanup failure\n"
626 8 foreach ( sort keys %failed );
627 8 ▶ return unless (@keys);
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 1 7 8
628 7 my $delErr;
629 _pipelined(
630 $redisObj,
631 7 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
632 7 foreach (@keys) {
633 $redisObj->del(
634 $_,
635 7 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
636 7 ▶ if ( defined $_[1] ) { $delErr //= "[del] $_[1]\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) { } 1 6 7
Condition50%1/2
$delErr //= "[del] $_[1]\n"
l!l
01
MC/DC0%0/1
$delErr //= "[del] $_[1]\n"
$delErr
Truth table50%1/2
A
A= $delErr
Aresult
11
00
637 6 else { $$deleted++ }
638 }
639 8 );
640 }
641 }
642 7 );
643 6 ▶ die $delErr if ( defined $delErr );
Branch: 1 branch
BranchTrueFalseTotal
if defined $delErr 1 5 6
644 }
645  
646 # Sends the commands queued by $code and waits for their answers. If sending
647 # dies (connection lost), the callbacks already queued are run before dying
648 18 ▶sub _pipelined {
Subroutine _pipelined: called CC=2 SCAR=6.9
649 18 my ( $redisObj, $code ) = @_;
650 18 ▶ eval { $code->(); $redisObj->wait_all_responses; 1 } and return;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$code(); $redisObj->wait_all_responses; 1 } } and return 15 3 18
651 3 my $err = $@;
652 3 eval { $redisObj->wait_all_responses };
653 3 die $err;
654 }
655  
656 0 ▶sub extractFields {
Subroutine extractFields: not called CC=3 SCAR=24.8
Pod undocumented
657 0 my ( $class, $entry, @fields ) = @_;
658 0 my $res;
659 0 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 0 0 0
660 0 $res->{$_} = $entry->{$_} foreach (@fields);
661 }
662 else {
663 0 $res = $entry;
664 }
665 0 return $res;
666 }
667  
668 0 ▶sub isIndexed {
Subroutine isIndexed: not called CC=2 SCAR=17.9
Pod undocumented
669 0 my ( $class, $args, $field ) = @_;
670 my $indexes =
671 0 ▶ ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{'Index'} ? : 0 0 0
672 0 return grep { $_ eq $field } @$indexes;
673 }
674  
675 10 my %keysRe_re;
676 52 ▶sub isLlngKey {
Subroutine isLlngKey: called CC=3 SCAR=11.0
Pod undocumented
677 52 my ( $class, $args, $name ) = @_;
678 52 ▶ my $expr = $args->{keysRe} || '^[0-9a-f]{32,}$';
Condition100%2/2
$args->{'keysRe'} || '^[0-9a-f]{32,}$'
l!l
250
MC/DC100%1/1
$args->{'keysRe'} || '^[0-9a-f]{32,}$'
$args->{'keysRe'}
Truth table100%2/2
A
A= $args->{'keysRe'}
Aresult
11
00
679  
680 # Compile per expression: a process may use several keysRe
681 52 ▶ $keysRe_re{$expr} = qr/$expr/ unless ( exists $keysRe_re{$expr} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $keysRe_re{$expr} 3 49 52
682 52 return ( $name =~ $keysRe_re{$expr} );
683 }
684  
685 2 ▶sub get_key_from_all_sessions {
Subroutine get_key_from_all_sessions: called CC=1 SCAR=0.8
Pod undocumented
686 2 my ( $class, $args, $data ) = @_;
687 2 my %res;
688 $class->_scanSessions(
689 $args,
690 4 ▶ sub {
Subroutine __ANON__: called CC=8 SCAR=28.4
691 4 foreach ( @{ $_[0] } ) {
692 8 my ( $k, $v ) = @$_;
693 8 eval {
694 8 my $tmp = unserialize($v);
695 8 ▶ if ( ref($data) eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'CODE') { } 0 8 8
elsif ($data) { } 0 8 8
696 0 $tmp = &$data( $tmp, $k );
697 0 ▶ $res{$k} = $tmp if ( defined($tmp) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $tmp 0 0 0
698 }
699 elsif ($data) {
700 0 ▶ $data = [$data] unless ( ref($data) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 0 0 0
701 0 $res{$k}->{$_} = $tmp->{$_} foreach (@$data);
702 }
703 else {
704 8 $res{$k} = $tmp;
705 }
706 };
707 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
708 0 print STDERR "Error in session $k: $@\n";
709  
710 # Don't delete, it may own to another app
711 #delete $res{$k};
712 }
713 }
714 }
715 2 );
716 2 return \%res;
717 }
718  
719 # Calls $code->( [ [ $key, $serialized ], ... ] ) for each batch of sessions:
720 # the keys of a SCAN call ($SCAN_COUNT) that match keysRe, read with MGET.
721 # MGET gives undef for a key of another type (an index set or hash) or
722 # deleted meanwhile: such keys are skipped, without a TYPE round trip per key,
723 # as empty values are
724 9 ▶sub _scanSessions {
Subroutine _scanSessions: called CC=6 SCAR=18.0
725 9 my ( $class, $args, $code, $redisObj ) = @_;
726 9 ▶ $redisObj ||= $class->_getRedis($args);
Condition66%2/3
$redisObj ||= $class->_getRedis($args)
l!l&&r!l&&!r
720
MC/DC0%0/2
$redisObj ||= $class->_getRedis($args)
$redisObj $class->_getRedis($args)
Truth table66%2/3
A ||= B
A= $redisObjB= $class->_getRedis($args)
ABresult
1X1
011
000
727 9 my $cursor = 0;
728 9 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$cursor != 0 and do { do { () = $redisObj->scan($cursor, "COUNT", $Web::Session::Redis::SCAN_COUNT); my(@keys) = grep({$class->isLlngKey($args, $_);} @$keys); if (@keys) { my(@values) = _mget($redisObj, @keys); &$code([map({length($values[$_] // "") ? [$keys[$_], $values[$_]] : ();} 0 .. $#keys)]); } ; $cursor = $new_cursor } } 6 4 10
729 15 my ( $new_cursor, $keys ) =
730 $redisObj->scan( $cursor, 'COUNT', $SCAN_COUNT );
731 15 my @keys = grep { $class->isLlngKey( $args, $_ ) } @$keys;
732 15 ▶ if (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) 15 0 15
733 15 my @values = _mget( $redisObj, @keys );
734 $code->(
735 [
736 15 ▶ map { length( $values[$_] // '' ) ? [ $keys[$_], $values[$_] ] : () }
Branch: 1 branch
BranchTrueFalseTotal
length($values[$_] // '') ? : 33 1 34
Condition50%1/2
$values[$_] // ""
l!l
340
MC/DC0%0/1
$values[$_] // ""
$values[$_]
Truth table50%1/2
A
A= $values[$_]
Aresult
11
00
737 0 .. $#keys
738 ]
739 );
740 }
741 10 $cursor = $new_cursor;
742 } while ( $cursor != 0 );
743 }
744  
745 0 ▶sub _getRedis {
Subroutine _getRedis: not called CC=1 SCAR=6.9
746 0 my ( $class, $args ) = @_;
747 0 return Web::Session::Store::Redis->_getRedis($args);
748 }
749  
750 10 1;
751 __END__
« Session/MySQLJSON.pm ↑ Summary Session/LDAP.pm »