| 1 | package Async::Redis::Iterator; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 91 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 91 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 91 | ▶ | use 5.018; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 91 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 10 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | return bless { | ||||||||||||||||||||||||||||||||
| 13 | redis => $args{redis}, | ||||||||||||||||||||||||||||||||
| 14 | command => $args{command} // 'SCAN', | ||||||||||||||||||||||||||||||||
| 15 | key => $args{key}, # For HSCAN/SSCAN/ZSCAN | ||||||||||||||||||||||||||||||||
| 16 | match => $args{match}, | ||||||||||||||||||||||||||||||||
| 17 | count => $args{count}, | ||||||||||||||||||||||||||||||||
| 18 | type => $args{type}, # For SCAN TYPE filter | ||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | cursor => 0, | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"command"} // "SCAN"
MC/DC0%0/1
$args{"command"} // "SCAN"
$args{"command"}
Truth table0%0/2
A
A= $args{"command"}
| |||||||||||||||||||||||||||||||||
| 20 | done => 0, | ||||||||||||||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | async sub next { | ||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 25 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # Already exhausted | ||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return undef if $self->{done}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | my @args; | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | # Build command args based on scan type | ||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($self->{command} eq 'SCAN') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 0 | @args = ($self->{cursor}); | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||||||
| 37 | # HSCAN, SSCAN, ZSCAN take key first, then cursor | ||||||||||||||||||||||||||||||||
| 38 | 0 | @args = ($self->{key}, $self->{cursor}); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | # Add MATCH pattern if specified | ||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (defined $self->{match}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 0 | push @args, 'MATCH', $self->{match}; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | # Add COUNT hint if specified | ||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (defined $self->{count}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 0 | push @args, 'COUNT', $self->{count}; | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | # Add TYPE filter for SCAN (Redis 6.0+) | ||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($self->{command} eq 'SCAN' && defined $self->{type}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"command"} eq "SCAN" and defined $self->{"type"}
MC/DC0%0/2
$self->{"command"} eq "SCAN" and defined $self->{"type"}
$self->{"command"} eq "SCAN"
defined $self->{"type"}
Truth table0%0/3
A and B
A= $self->{"command"} eq "SCAN"B= defined $self->{"type"}
| |||||||||||||||||||||||||||||||||
| 53 | 0 | push @args, 'TYPE', $self->{type}; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | # Execute scan command | ||||||||||||||||||||||||||||||||
| 57 | 0 | my $result = await $self->{redis}->command($self->{command}, @args); | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | # Result is [cursor, [elements...]] | ||||||||||||||||||||||||||||||||
| 60 | 0 | my ($new_cursor, $elements) = @$result; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | # Update cursor | ||||||||||||||||||||||||||||||||
| 63 | 0 | $self->{cursor} = $new_cursor; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | # Check if iteration complete (cursor returned to 0) | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($new_cursor eq '0' || $new_cursor == 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$new_cursor eq 0 or $new_cursor == 0
MC/DC0%0/2
$new_cursor eq 0 or $new_cursor == 0
$new_cursor eq 0
$new_cursor == 0
Truth table0%0/3
A or B
A= $new_cursor eq 0B= $new_cursor == 0
| |||||||||||||||||||||||||||||||||
| 67 | 0 | $self->{done} = 1; | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | # Return batch (may be empty) | ||||||||||||||||||||||||||||||||
| 71 | # Return undef only when done AND no elements in final batch | ||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return $elements && @$elements ? $elements : ($self->{done} ? undef : []); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$elements and @$elements
MC/DC0%0/2
$elements and @$elements
$elements
@$elements
Truth table0%0/3
A and B
A= $elementsB= @$elements
| |||||||||||||||||||||||||||||||||
| 73 | 91 | } | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub reset { | ||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 76 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 77 | 0 | $self->{cursor} = 0; | |||||||||||||||||||||||||||||||
| 78 | 0 | $self->{done} = 0; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub cursor { shift->{cursor} } | ||||||||||||||||||||||||||||||
|
Subroutine
cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub done { shift->{done} } | ||||||||||||||||||||||||||||||
|
Subroutine
done: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 91 | 1; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||