Redis/Server/Database.pm

filter: Statementstmt 13.1% 11 / 84 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 14.2% 3 / 21 Podpod 0.0% 0 / 18 totaltotal 8.4% 14 / 166 CC 18 SCAR 41.7
CC
18
Cov
9%
set
182.0
keys
12.0
exists
6.0
CRAP 64.9
↑ Summary Redis.pm »
1 package Net::Async::Redis::Server::Database;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '2.004_001'; # TRIAL VERSION
7  
8 =head1 NAME
9  
10 Net::Async::Redis::Server::Database - implementation for database-related Redis commands
11  
12 =head1 DESCRIPTION
13  
14 See L<Net::Async::Redis::Commands> for the full list of commands.
15  
16 Most of them are not yet implemented.
17  
18 =cut
19  
20 2 ▶use Math::Random::Secure ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 sub set : method {
23 0 ▶ my ($self, $k, $v, @args) = @_;
Subroutine set: not called CC=13 SCAR=52.0
Pod undocumented
24 0 my %opt;
25 0 ▶ while(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
26 0 my $cmd = shift @args;
27 0 ▶ if($cmd eq 'EX') {
Branch: 4 branches
BranchTrueFalseTotal
if ($cmd eq 'EX') { } 0 0 0
elsif ($cmd eq 'PX') { } 0 0 0
elsif ($cmd eq 'NX') { } 0 0 0
elsif ($cmd eq 'XX') { } 0 0 0
28 0 $opt{ttl} = 1000 * shift @args;
29 } elsif($cmd eq 'PX') {
30 0 $opt{ttl} = shift @args;
31 } elsif($cmd eq 'NX') {
32 0 ▶ die 'Cannot set NX and XX' if exists $opt{xx};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"xx"} 0 0 0
33 0 $opt{nx} = 1;
34 } elsif($cmd eq 'XX') {
35 0 ▶ die 'Cannot set NX and XX' if exists $opt{nx};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{"nx"} 0 0 0
36 0 $opt{xx} = 1;
37 } else {
38 0 die 'Invalid input: ' . $cmd
39 }
40 }
41 0 ▶ return Future->done(undef) if not exists $self->{keys}{$k} and $opt{xx};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $self->{"keys"}{$k} and $opt{"xx"} 0 0 0
Condition0%0/3
not exists $self->{"keys"}{$k} and $opt{"xx"}
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $self->{"keys"}{$k} and $opt{"xx"}
not exists $self->{"keys"}{$k} $opt{"xx"}
Truth table0%0/3
not(A) and B
A= not exists $self->{"keys"}{$k}B= $opt{"xx"}
ABresult
0X0
100
111
42 0 ▶ return Future->done(undef) if exists $self->{keys}{$k} and $opt{nx};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"keys"}{$k} and $opt{"nx"} 0 0 0
Condition0%0/3
exists $self->{"keys"}{$k} and $opt{"nx"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"keys"}{$k} and $opt{"nx"}
exists $self->{"keys"}{$k} $opt{"nx"}
Truth table0%0/3
A and B
A= exists $self->{"keys"}{$k}B= $opt{"nx"}
ABresult
0X0
100
111
43 0 $self->{keys}{$k} = $v;
44 0 ▶ if(exists $opt{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt{"ttl"}) 0 0 0
45 0 $self->{expiry}{$k} = $opt{ttl} + $self->time;
46 }
47 0 return Future->done('OK');
48 }
49  
50 sub get : method {
51 0 ▶ my ($self, $k) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
52 0 return Future->done($self->{keys}{$k});
53 }
54  
55 sub auth : method {
56 0 ▶ my ($self, $auth) = @_;
Subroutine auth: not called CC=1 SCAR=6.9
Pod undocumented
57 0 return Future->done('OK');
58 }
59  
60 sub echo : method {
61 0 ▶ my ($self, $string) = @_;
Subroutine echo: not called CC=1 SCAR=6.9
Pod undocumented
62 0 return Future->done($string);
63 }
64  
65 sub ping : method {
66 0 ▶ my ($self, $string) = @_;
Subroutine ping: not called CC=1 SCAR=6.9
Pod undocumented
67 0 return Future->done(PONG => $string);
68 }
69  
70 sub quit : method {
71 0 ▶ my ($self, $string) = @_;
Subroutine quit: not called CC=1 SCAR=6.9
Pod undocumented
72 0 $self->connection->close;
73 0 return Future->done('OK');
74 }
75  
76 sub del : method {
77 0 ▶ my ($self, @keys) = @_;
Subroutine del: not called CC=1 SCAR=6.9
Pod undocumented
78 0 return Future->done(delete @{$self->{keys}}{@keys});
79 }
80  
81 sub exists : method {
82 0 ▶ my ($self, @keys) = @_;
Subroutine exists: not called CC=2 SCAR=17.9
Pod undocumented
83 0 ▶ return Future->done(map { exists $self->{keys}{$_} ? 1 : 0 } @keys);
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'keys'}{$_} ? : 0 0 0
84 }
85  
86 sub expire : method {
87 0 ▶ my ($self, $k, $ttl) = @_;
Subroutine expire: not called CC=1 SCAR=6.9
Pod undocumented
88 0 return $self->pexpire($k => 1000 * $ttl);
89 }
90  
91 sub expireat : method {
92 0 ▶ my ($self, $k, $time) = @_;
Subroutine expireat: not called CC=1 SCAR=6.9
Pod undocumented
93 0 return $self->pexpireat($k => 1000 * $time);
94 }
95  
96 sub pexpire : method {
97 0 ▶ my ($self, $k, $ttl) = @_;
Subroutine pexpire: not called CC=2 SCAR=17.9
Pod undocumented
98 0 ▶ $self->{expiry}{$k} = $ttl + $self->time if exists $self->{keys}{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"keys"}{$k} 0 0 0
99 0 return Future->done('OK');
100 }
101  
102 sub pexpireat : method {
103 0 ▶ my ($self, $k, $time) = @_;
Subroutine pexpireat: not called CC=2 SCAR=17.9
Pod undocumented
104 0 ▶ $self->{expiry}{$k} = $time if exists $self->{keys}{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"keys"}{$k} 0 0 0
105 0 return Future->done('OK');
106 }
107  
108 sub keys : method {
109 0 ▶ my ($self, $pattern) = @_;
Subroutine keys: not called CC=3 SCAR=24.8
Pod undocumented
110 0 ▶ $pattern = '*' unless defined($pattern) and length($pattern);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern and length $pattern 0 0 0
Condition0%0/3
defined $pattern and length $pattern
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pattern and length $pattern
defined $pattern length $pattern
Truth table0%0/3
A and B
A= defined $patternB= length $pattern
ABresult
0X0
100
111
111 0 $pattern = qr/^\Q$pattern\E$/;
112 0 $pattern =~ s{\\\*}{.*}g;
113 0 return Future->done(grep { $_ =~ $pattern } sort keys %{$self->{keys}});
114 }
115  
116 sub persist : method {
117 0 ▶ my ($self, $k) = @_;
Subroutine persist: not called CC=1 SCAR=6.9
Pod undocumented
118 0 delete $self->{expiry}{$k};
119 0 return Future->done('OK');
120 }
121  
122 sub randomkey : method {
123 0 ▶ my ($self) = @_;
Subroutine randomkey: not called CC=1 SCAR=6.9
Pod undocumented
124 0 return Future->done((keys %{$self->{keys}})[Math::Random::Secure::irand keys %{$self->{keys}}]);
125 }
126  
127 sub lpush : method {
128 0 ▶ my ($self, $k, @values) = @_;
Subroutine lpush: not called CC=1 SCAR=6.9
Pod undocumented
129 0 unshift @{$self->{keys}{$k}}, @values;
130 0 return Future->done('OK');
131 }
132  
133 sub rpush : method {
134 0 ▶ my ($self, $k, @values) = @_;
Subroutine rpush: not called CC=1 SCAR=6.9
Pod undocumented
135 0 push @{$self->{keys}{$k}}, @values;
136 0 return Future->done('OK');
137 }
138  
139 sub brpoplpush : method {
140 0 ▶ my ($self, $src, $dst, $timeout) = @_;
Subroutine brpoplpush: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my $v = pop @{$self->{keys}{$src}};
142 0 unshift @{$self->{keys}{$dst}}, $v;
143 0 return Future->done($v);
144 }
145  
146 2 1;
147  
148 =head1 AUTHOR
149  
150 Tom Molesworth C<< <TEAM@cpan.org> >> plus contributors as mentioned in
151 L<Net::Async::Redis/CONTRIBUTORS>.
152  
153 =head1 LICENSE
154  
155 Copyright Tom Molesworth 2015-2020. Licensed under the same terms as Perl itself.
156  
↑ Summary Redis.pm »