ShardedKV/Storage/Redis/String.pm

filter: Statementstmt 36.8% 21 / 57 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 32.9% 29 / 88 CC 10 SCAR 31.8
CC
10
Cov
28%
set
42.0
get
30.0
BEGIN
1.0
CRAP 24.0
« ShardedKV/Storage/Redis/Hash.pm ↑ Summary ShardedKV/Storage/MySQL.pm »
1 package ShardedKV::Storage::Redis::String;
2 3 $ShardedKV::Storage::Redis::String::VERSION = '0.20';
3 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 # ABSTRACT: Storing simple string values in Redis
5 3 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use ShardedKV::Error::ReadFail;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use ShardedKV::Error::WriteFail;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'ShardedKV::Storage::Redis';
11  
12 0 ▶sub get {
Subroutine get: not called CC=5 SCAR=34.0
Pod documented
13 0 my ($self, $key) = @_;
14 0 my $redis = $self->redis;
15 0 my $str;
16 eval {
17 0 my $foo = $redis->get($key);
18 0 ▶ if(defined($foo)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $foo) 0 0 0
19 0 $str = $foo;
20 }
21 0 1;
22 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $foo = $redis->get($key); if (defined $foo) { $str = $foo; } ; 1 } } or do { my $error = $@ || "Zombie Error"; my $endpoint = $self->redis_connect_str; $self->reset_connection; "ShardedKV::Error::ReadFail"->throw({"endpoint", $endpoint, "key", $key, "storage_type", "redis", "message", "Failed to fetch key ($key) from Redis ($endpoint): $error"}) } 0 0 0
23 0 ▶ my $error = $@ || "Zombie Error";
Condition0%0/2
$@ || 'Zombie Error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
24 0 my $endpoint = $self->redis_connect_str;
25 0 $self->reset_connection;
26 0 ShardedKV::Error::ReadFail->throw({
27 endpoint => $endpoint,
28 key => $key,
29 storage_type => 'redis',
30 message => "Failed to fetch key ($key) from Redis ($endpoint): $error",
31 });
32 };
33
34 0 ▶ if(defined($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str) { } 0 0 0
35 0 Encode::_utf8_on($str); # FIXME wrong, wrong, wrong, but Redis.pm would otherwise call encode() all the time
36 0 return \$str;
37 } else {
38 0 return undef;
39 }
40 }
41  
42 0 ▶sub set {
Subroutine set: not called CC=6 SCAR=37.4
Pod documented
43 0 my ($self, $key, $value_ref) = @_;
44 0 my $r = $self->redis;
45  
46 0 my $rv;
47 eval {
48 0 $rv = $r->set($key, $$value_ref);
49 0 1;
50 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $rv = $r->set($key, $$value_ref); 1 } } or do { my $error = $@ || "Zombie Error"; my $endpoint = $self->redis_connect_str; $self->reset_connection; "ShardedKV::Error::WriteFail"->throw({"endpoint", $endpoint, "key", $key, "storage_type", "redis", "operation", "set", "message", "Failed to store key ($key) to Redis ($endpoint): $error"}) } 0 0 0
51 0 ▶ my $error = $@ || "Zombie Error";
Condition0%0/2
$@ || 'Zombie Error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
52 0 my $endpoint = $self->redis_connect_str;
53 0 $self->reset_connection;
54 0 ShardedKV::Error::WriteFail->throw({
55 endpoint => $endpoint,
56 key => $key,
57 storage_type => 'redis',
58 operation => 'set',
59 message => "Failed to store key ($key) to Redis ($endpoint): $error",
60 });
61 };
62  
63 0 my $expire = $self->expiration_time;
64 0 ▶ if (defined $expire) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $expire) 0 0 0
65 eval {
66 0 $r->pexpire(
67 $key, int(1000*($expire+rand($self->expiration_time_jitter)))
68 );
69 0 1;
70 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $r->pexpire($key, int 1000 * ($expire + rand($self->expiration_time_jitter))); 1 } } or do { my $error = $@ || "Zombie Error"; my $endpoint = $self->redis_connect_str; $self->reset_connection; "ShardedKV::Error::WriteFail"->throw({"endpoint", $endpoint, "key", $key, "storage_type", "redis", "operation", "expire", "message", "Failed to store key ($key) to Redis ($endpoint): $error"}) } 0 0 0
71 0 ▶ my $error = $@ || "Zombie Error";
Condition0%0/2
$@ || 'Zombie Error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
72 0 my $endpoint = $self->redis_connect_str;
73 0 $self->reset_connection;
74 0 ShardedKV::Error::WriteFail->throw({
75 endpoint => $endpoint,
76 key => $key,
77 storage_type => 'redis',
78 operation => 'expire',
79 message => "Failed to store key ($key) to Redis ($endpoint): $error",
80 });
81 };
82 }
83  
84 0 return $rv;
85 }
86  
87 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 3 __PACKAGE__->meta->make_immutable;
89  
90 =pod
91  
92 =head1 NAME
93  
94 ShardedKV::Storage::Redis::String - Storing simple string values in Redis
95  
96 =head1 VERSION
97  
98 version 0.20
99  
100 =head1 SYNOPSIS
101  
102 use ShardedKV;
103 use ShardedKV::Storage::Redis::String;
104 ... create ShardedKV...
105 my $storage = ShardedKV::Storage::Redis::String->new(
106 redis_connect_str => 'redisshard1:679',
107 expiration_time => 60*60, #1h
108 );
109 ... put storage into ShardedKV...
110
111 # values are scalar references to strings
112 $skv->set("foo", \"bar");
113 my $value_ref = $skv->get("foo");
114  
115 =head1 DESCRIPTION
116  
117 This subclass of L<ShardedKV::Storage::Redis> implements
118 simple string/blob values in Redis. See the documentation
119 for C<ShardedKV::Storage::Redis> for the interface of this
120 class.
121  
122 The values of a C<ShardedKV::Storage::Redis::String> are
123 actually scalar references to strings.
124  
125 =head1 SEE ALSO
126  
127 =over 4
128  
129 =item *
130  
131 L<ShardedKV>
132  
133 =item *
134  
135 L<ShardedKV::Storage>
136  
137 =item *
138  
139 L<ShardedKV::Storage::Redis>
140  
141 =item *
142  
143 L<ShardedKV::Storage::Redis::Hash>
144  
145 =back
146  
147 =head1 AUTHORS
148  
149 =over 4
150  
151 =item *
152  
153 Steffen Mueller <smueller@cpan.org>
154  
155 =item *
156  
157 Nick Perez <nperez@cpan.org>
158  
159 =item *
160  
161 Damian Gryski <dgryski@cpan.org>
162  
163 =back
164  
165 =head1 COPYRIGHT AND LICENSE
166  
167 This software is copyright (c) 2013 by Steffen Mueller.
168  
169 This is free software; you can redistribute it and/or modify it under
170 the same terms as the Perl 5 programming language system itself.
171  
172 =cut
173  
174 __END__
« ShardedKV/Storage/Redis/Hash.pm ↑ Summary ShardedKV/Storage/MySQL.pm »