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
« Redis.pm ↑ Summary Redis/Cluster/Node.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 = '6.006'; # 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 0 ▶sub set : method {
Subroutine set: not called CC=13 SCAR=52.0
Pod undocumented
23 0 my ($self, $k, $v, @args) = @_;
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 0 ▶sub get : method {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($self, $k) = @_;
52 0 return Future->done($self->{keys}{$k});
53 }
54  
55 0 ▶sub auth : method {
Subroutine auth: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self, $auth) = @_;
57 0 return Future->done('OK');
58 }
59  
60 0 ▶sub echo : method {
Subroutine echo: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my ($self, $string) = @_;
62 0 return Future->done($string);
63 }
64  
65 0 ▶sub ping : method {
Subroutine ping: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ($self, $string) = @_;
67 0 return Future->done(PONG => $string);
68 }
69  
70 0 ▶sub quit : method {
Subroutine quit: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my ($self, $string) = @_;
72 0 $self->connection->close;
73 0 return Future->done('OK');
74 }
75  
76 0 ▶sub del : method {
Subroutine del: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my ($self, @keys) = @_;
78 0 return Future->done(delete @{$self->{keys}}{@keys});
79 }
80  
81 0 ▶sub exists : method {
Subroutine exists: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my ($self, @keys) = @_;
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 0 ▶sub expire : method {
Subroutine expire: not called CC=1 SCAR=6.9
Pod undocumented
87 0 my ($self, $k, $ttl) = @_;
88 0 return $self->pexpire($k => 1000 * $ttl);
89 }
90  
91 0 ▶sub expireat : method {
Subroutine expireat: not called CC=1 SCAR=6.9
Pod undocumented
92 0 my ($self, $k, $time) = @_;
93 0 return $self->pexpireat($k => 1000 * $time);
94 }
95  
96 0 ▶sub pexpire : method {
Subroutine pexpire: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my ($self, $k, $ttl) = @_;
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 0 ▶sub pexpireat : method {
Subroutine pexpireat: not called CC=2 SCAR=17.9
Pod undocumented
103 0 my ($self, $k, $time) = @_;
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 0 ▶sub keys : method {
Subroutine keys: not called CC=3 SCAR=24.8
Pod undocumented
109 0 my ($self, $pattern) = @_;
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 0 ▶sub persist : method {
Subroutine persist: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ($self, $k) = @_;
118 0 delete $self->{expiry}{$k};
119 0 return Future->done('OK');
120 }
121  
122 0 ▶sub randomkey : method {
Subroutine randomkey: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my ($self) = @_;
124 0 return Future->done((keys %{$self->{keys}})[Math::Random::Secure::irand keys %{$self->{keys}}]);
125 }
126  
127 0 ▶sub lpush : method {
Subroutine lpush: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my ($self, $k, @values) = @_;
129 0 unshift @{$self->{keys}{$k}}, @values;
130 0 return Future->done('OK');
131 }
132  
133 0 ▶sub rpush : method {
Subroutine rpush: not called CC=1 SCAR=6.9
Pod undocumented
134 0 my ($self, $k, @values) = @_;
135 0 push @{$self->{keys}{$k}}, @values;
136 0 return Future->done('OK');
137 }
138  
139 0 ▶sub brpoplpush : method {
Subroutine brpoplpush: not called CC=1 SCAR=6.9
Pod undocumented
140 0 my ($self, $src, $dst, $timeout) = @_;
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-2024. Licensed under the same terms as Perl itself.
156  
« Redis.pm ↑ Summary Redis/Cluster/Node.pm »