Redis.pm

filter: Statementstmt 20.9% 68 / 324 Branchbran 0.0% 0 / 100 Conditioncond 0.0% 0 / 88 MC/DCmcdc 0.0% 0 / 54 Subroutinesub 31.1% 19 / 61 Podpod 57.5% 19 / 33 totaltotal 16.0% 106 / 660 CC 89 SCAR 39.7
CC
89
Cov
13%
handle_pubsub_message
210.0
configure
182.0
connect
72.0
CRAP 52.9
« Redis/Server/Database.pm ↑ Summary Redis/Multi.pm »
1 package Net::Async::Redis;
2 # ABSTRACT: Redis support for IO::Async
3  
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 use parent qw(
8 Net::Async::Redis::Commands
9 IO::Async::Notifier
10 10 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 10 our $VERSION = '2.004_001';
13  
14 =head1 NAME
15  
16 Net::Async::Redis - talk to Redis servers via L<IO::Async>
17  
18 =head1 SYNOPSIS
19  
20 use Net::Async::Redis;
21 use Future::AsyncAwait;
22 use IO::Async::Loop;
23 my $loop = IO::Async::Loop->new;
24 $loop->add(my $redis = Net::Async::Redis->new);
25 (async sub {
26 await $redis->connect;
27 my $value = await $redis->get('some_key');
28 $value ||= await $redis->set(some_key => 'some_value');
29 print "Value: $value";
30 })->()->get;
31  
32 # You can also use ->then chaining, see L<Future> for more details
33 $redis->connect->then(sub {
34 $redis->get('some_key')
35 })->then(sub {
36 my $value = shift;
37 return Future->done($value) if $value;
38 $redis->set(some_key => 'some_value')
39 })->on_done(sub {
40 print "Value: " . shift;
41 })->get;
42  
43 # ... or with Future::AsyncAwait
44 await $redis->connect;
45 my $value = await $redis->get('some_key');
46 $value ||= await $redis->set(some_key => 'some_value');
47 print "Value: $value";
48  
49 =head1 DESCRIPTION
50  
51 Provides client access for dealing with Redis servers.
52  
53 See L<Net::Async::Redis::Commands> for the full list of commands, this list
54 is autogenerated from the official documentation here:
55  
56 L<https://redis.io/commands>
57  
58 This is intended to be a near-complete low-level client module for asynchronous Redis
59 support. See L<Net::Async::Redis::Server> for a (limited) Perl server implementation.
60 It is an unofficial Perl port and not endorsed by the Redis server maintainers in any
61 way.
62  
63 =head2 Supported features
64  
65 Current features include:
66  
67 =over 4
68  
69 =item * L<all commands|https://redis.io/commands> as of 6.0 (May 2020), see L<https://redis.io/commands> for the methods and parameters
70  
71 =item * L<pub/sub support|https://redis.io/topics/pubsub>, see L</Subscriptions>
72  
73 =item * L<pipelining|https://redis.io/topics/pipelining>, see L</Pipelining>
74  
75 =item * L<transactions|https://redis.io/topics/transactions>, see L</Transactions>
76  
77 =item * L<streams|https://redis.io/topics/streams-intro> and consumer groups, see L</Streams>
78  
79 =back
80  
81 =head2 Connecting
82  
83 As with any other L<IO::Async::Notifier>-based module, you'll need to
84 add this to an L<IO::Async::Loop>:
85  
86 my $loop = IO::Async::Loop->new;
87 $loop->add(
88 my $redis = Net::Async::Redis->new
89 );
90  
91 then connect to the server:
92  
93 $redis->connect
94 ->then(sub {
95 # You could achieve a similar result by passing client_name in
96 # constructor or ->connect parameters
97 $redis->client_setname("example client")
98 })->get;
99  
100 =head2 Key-value handling
101  
102 One of the most common Redis scenarios is as a key/value store. The L</get> and L</set>
103 methods are typically used here:
104  
105 $redis->set(some_key => 'some value')
106 ->then(sub {
107 $redis->get('some_key')
108 })->on_done(sub {
109 my ($value) = @_;
110 print "Read back value [$value]\n";
111 })->retain;
112  
113 See the next section for more information on what these methods are actually returning.
114  
115 =head2 Requests and responses
116  
117 Requests are implemented as methods on the L<Net::Async::Redis> object.
118 These typically return a L<Future> which will resolve once ready:
119  
120 my $future = $redis->incr("xyz")
121 ->on_done(sub {
122 print "result of increment was " . shift . "\n"
123 });
124  
125 For synchronous code, call C<< ->get >> on that L<Future>:
126  
127 print "Database has " . $redis->dbsize->get . " total keys\n";
128  
129 This means you can end up with C<< ->get >> being called on the result of C<< ->get >>,
130 note that these are two very different methods:
131  
132 $redis
133 ->get('some key') # this is being called on $redis, and is issuing a GET request
134 ->get # this is called on the returned Future, and blocks until the value is ready
135  
136 Typical async code would not be expected to use the L<Future/get> method extensively;
137 often only calling it in one place at the top level in the code.
138  
139 =head2 Error handling
140  
141 Since L<Future> is used for deferred results, failure is indicated
142 by a failing Future with L<failure category|Future/FAILURE-CATEGORIES>
143 of C<redis>.
144  
145 The L<Future/catch> feature may be useful for handling these:
146  
147 $redis->lpush(key => $value)
148 ->catch(
149 redis => sub { warn "probably an incorrect type, cannot push value"; Future->done }
150 )->get;
151  
152 Note that this module uses L<Future::AsyncAwait> internally.
153  
154 =cut
155  
156 10 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 10 ▶use Class::Method::Modifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
158 10 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 10 ▶use curry::weak;
Subroutine BEGIN: called CC=1 SCAR=0.0
160 10 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
161 10 ▶use IO::Async::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
162 10 ▶use Ryu::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
163 10 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
164 10 ▶use URI::redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
165 10 ▶use Cache::LRU;
Subroutine BEGIN: called CC=1 SCAR=0.0
166  
167 10 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
168  
169 10 ▶use List::Util qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
170 10 ▶use Scalar::Util qw(reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
171  
172 10 ▶use Net::Async::Redis::Multi;
Subroutine BEGIN: called CC=1 SCAR=0.0
173 10 ▶use Net::Async::Redis::Subscription;
Subroutine BEGIN: called CC=1 SCAR=0.0
174 10 ▶use Net::Async::Redis::Subscription::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
175  
176 10 our %ALLOWED_SUBSCRIPTION_COMMANDS = (
177 SUBSCRIBE => 1,
178 PSUBSCRIBE => 1,
179 UNSUBSCRIBE => 1,
180 PUNSUBSCRIBE => 1,
181 PING => 1,
182 QUIT => 1,
183 );
184  
185 10 our %SUBSCRIPTION_COMMANDS = (
186 SUBSCRIBE => 1,
187 PSUBSCRIBE => 1,
188 UNSUBSCRIBE => 1,
189 PUNSUBSCRIBE => 1,
190 MESSAGE => 1,
191 PMESSAGE => 1,
192 );
193  
194  
195 =head1 METHODS
196  
197 B<NOTE>: For a full list of the Redis methods supported by this module,
198 please see L<Net::Async::Redis::Commands>.
199  
200 =cut
201  
202 =head1 METHODS - Subscriptions
203  
204 See L<https://redis.io/topics/pubsub> for more details on this topic.
205 There's also more details on the internal implementation in Redis here:
206 L<https://making.pusher.com/redis-pubsub-under-the-hood/>.
207  
208 =cut
209  
210 =head2 psubscribe
211  
212 Subscribes to a pattern.
213  
214 Example:
215  
216 # Subscribe to 'info::*' channels, i.e. any message
217 # that starts with the C<info::> prefix, and prints them
218 # with a timestamp.
219 $redis_connection->psubscribe('info::*')
220 ->then(sub {
221 my $sub = shift;
222 $sub->map('payload')
223 ->each(sub {
224 print localtime . ' ' . $_ . "\n";
225 })->retain
226 })->get;
227 # this will block until the subscribe is confirmed. Note that you can't publish on
228 # a connection that's handling subscriptions due to Redis protocol restrictions.
229 $other_redis_connection->publish('info::example', 'a message here')->get;
230  
231 Returns a L<Future> which resolves to a L<Net::Async::Redis::Subscription> instance.
232  
233 =cut
234  
235 0 ▶async sub psubscribe {
Subroutine psubscribe: not called CC=4 SCAR=30.0
Pod documented
236 0 my ($self, $pattern) = @_;
237 0 await $self->next::method($pattern);
238 0 ▶ $self->{pubsub} //= 0;
Condition0%0/2
$self->{"pubsub"} //= 0
l!l
00
MC/DC0%0/1
$self->{"pubsub"} //= 0
$self->{"pubsub"}
Truth table0%0/2
A
A= $self->{"pubsub"}
Aresult
11
00
239 0 ▶ $self->{pending_subscription_pattern_channel}{$pattern} //= $self->future('pattern_subscription[' . $pattern . ']');
Condition0%0/3
$self->{"pending_subscription_pattern_channel"}{$pattern} //= $self->future('pattern_subscription[' . $pattern . ']')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"pending_subscription_pattern_channel"}{$pattern} //= $self->future('pattern_subscription[' . $pattern . ']')
$self->{"pending_subscription_pattern_channel"}{$pattern} $self->future('pattern_subscription[' . $pattern . ']')
Truth table0%0/3
A //= B
A= $self->{"pending_subscription_pattern_channel"}{$pattern}B= $self->future('pattern_subscription[' . $pattern . ']')
ABresult
1X1
011
000
240 0 ▶ return $self->{subscription_pattern_channel}{$pattern} //= Net::Async::Redis::Subscription->new(
Condition0%0/3
$self->{"subscription_pattern_channel"}{$pattern} //= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $pattern)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"subscription_pattern_channel"}{$pattern} //= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $pattern)
$self->{"subscription_pattern_channel"}{$pattern} "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $pattern)
Truth table0%0/3
A //= B
A= $self->{"subscription_pattern_channel"}{$pattern}B= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $pattern)
ABresult
1X1
011
000
241 redis => $self,
242 channel => $pattern
243 )
244 10 }
245  
246 =head2 subscribe
247  
248 Subscribes to one or more channels.
249  
250 Returns a L<Future> which resolves to a L<Net::Async::Redis::Subscription> instance.
251  
252 Example:
253  
254 # Subscribe to 'notifications' channel,
255 # print the first 5 messages, then unsubscribe
256 $redis->subscribe('notifications')
257 ->then(sub {
258 my $sub = shift;
259 $sub->events
260 ->map('payload')
261 ->take(5)
262 ->say
263 ->completed
264 })->then(sub {
265 $redis->unsubscribe('notifications')
266 })->get
267  
268 =cut
269  
270 0 ▶async sub subscribe {
Subroutine subscribe: not called CC=3 SCAR=24.8
Pod documented
271 0 my ($self, @channels) = @_;
272 0 await $self->next::method(@channels);
273 0 $log->tracef('Marking as pubsub mode');
274 0 ▶ $self->{pubsub} //= 0;
Condition0%0/2
$self->{"pubsub"} //= 0
l!l
00
MC/DC0%0/1
$self->{"pubsub"} //= 0
$self->{"pubsub"}
Truth table0%0/2
A
A= $self->{"pubsub"}
Aresult
11
00
275 await Future->wait_all(
276 map {
277 0 ▶ $self->{pending_subscription_channel}{$_} //= $self->future('subscription[' . $_ . ']')
Condition0%0/3
$self->{"pending_subscription_channel"}{$_} //= $self->future('subscription[' . $_ . ']')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"pending_subscription_channel"}{$_} //= $self->future('subscription[' . $_ . ']')
$self->{"pending_subscription_channel"}{$_} $self->future('subscription[' . $_ . ']')
Truth table0%0/3
A //= B
A= $self->{"pending_subscription_channel"}{$_}B= $self->future('subscription[' . $_ . ']')
ABresult
1X1
011
000
278 } @channels
279 );
280 0 return @{$self->{subscription_channel}}{@channels};
281 10 }
282  
283 =head1 METHODS - Transactions
284  
285 =head2 multi
286  
287 Executes the given code in a Redis C<MULTI> transaction.
288  
289 This will cause each of the requests to be queued on the server, then applied in a single
290 atomic transaction.
291  
292 Note that the commands will resolve only after the transaction is committed: for example,
293 when the L</set> command is issued, Redis will return C<QUEUED>. This information
294 is B<not> used as the result - we only pass through the immediate
295 response if there was an error. The L<Future> representing
296 the response will be marked as done once the C<EXEC> command is applied and we have the
297 results back.
298  
299 Example:
300  
301 $redis->multi(sub {
302 my $tx = shift;
303 $tx->incr('some::key')->on_done(sub { print "Final value for incremented key was " . shift . "\n"; });
304 $tx->set('other::key => 'test data')
305 })->then(sub {
306 my ($success, $failure) = @_;
307 return Future->fail("Had $failure failures, expecting everything to succeed") if $failure;
308 print "$success succeeded\m";
309 return Future->done;
310 })->retain;
311  
312 =cut
313  
314 0 ▶async sub multi {
Subroutine multi: not called CC=4 SCAR=30.0
Pod documented
315 0 my ($self, $code) = @_;
316 0 ▶ die 'Need a coderef' unless $code and reftype($code) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $code and builtin::reftype($code) eq "CODE" 0 0 0
Condition0%0/3
$code and builtin::reftype($code) eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$code and builtin::reftype($code) eq "CODE"
$code builtin::reftype($code) eq "CODE"
Truth table0%0/3
A and B
A= $codeB= builtin::reftype($code) eq "CODE"
ABresult
0X0
100
111
317  
318 0 my $multi = Net::Async::Redis::Multi->new(
319 redis => $self,
320 );
321 0 my @pending = @{$self->{pending_multi}};
322  
323 0 $log->tracef('Have %d pending MULTI transactions',
324 0 + @pending
325 );
326 0 push @{$self->{pending_multi}}, $self->loop->new_future->set_label($self->command_label('multi'));
327  
328 0 ▶ await Future->wait_all(
Branch: 1 branch
BranchTrueFalseTotal
if @pending 0 0 0
329 @pending
330 ) if @pending;
331 0 await do {
332 0 local $self->{_is_multi} = 1;
333 0 Net::Async::Redis::Commands::multi($self);
334 };
335 0 return await $multi->exec($code)
336 10 }
337  
338 around [qw(discard exec)] => sub {
339 0 ▶ my ($code, $self, @args) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
340 0 local $self->{_is_multi} = 1;
341 0 my $f = $self->$code(@args);
342 0 (shift @{$self->{pending_multi}})->done;
343 0 $f->retain
344 10 };
345  
346 =head1 METHODS - Clientside caching
347  
348 Enable clientside caching by passing a true value for C<client_side_caching_enabled> in
349 L</configure> or L</new>. This is currently B<experimental>, and only operates on
350 L<Net::Async::Redis::Commands/get> requests.
351  
352 See L<https://redis.io/topics/client-side-caching> for more details on this feature.
353  
354 =cut
355  
356 0 ▶async sub client_side_connection {
Subroutine client_side_connection: not called CC=2 SCAR=17.9
Pod undocumented
357 0 my ($self) = @_;
358 0 ▶ return if $self->{client_side_connection};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"client_side_connection"} 0 0 0
359 0 my $f = $self->{client_side_cache_ready} = $self->loop->new_future;
360 $self->{client_side_connection} = my $redis = ref($self)->new(
361 host => $self->host,
362 port => $self->port,
363 auth => $self->{auth},
364 0 );
365 0 $self->add_child($redis);
366 0 my $id = await $redis->client_id;
367 0 my $sub = await $redis->subscribe('__redis__:invalidate');
368 $sub->events->each(sub {
369 0 ▶ $log->tracef('Invalidating key %s', $_->payload);
Subroutine __ANON__: not called CC=1 SCAR=6.9
370 0 $self->client_side_cache->remove($_->payload);
371 0 });
372 0 $f->done;
373 10 }
374  
375 sub client_side_cache_ready {
376 0 ▶ my ($self) = @_;
Subroutine client_side_cache_ready: not called CC=2 SCAR=17.9
Pod undocumented
377 0 ▶ my $f = $self->{client_side_cache_ready} or return Future->fail('client-side cache is not enabled');
Branch: 1 branch
BranchTrueFalseTotal
my $f = $self->{"client_side_cache_ready"} or return "Future"->fail("client-side cache is not enabled") 0 0 0
378 0 return $f->without_cancel;
379 }
380  
381 sub client_side_cache {
382 0 ▶ my ($self) = @_;
Subroutine client_side_cache: not called CC=2 SCAR=17.9
Pod undocumented
383 0 ▶ $self->{client_side_cache} //= Cache::LRU->new(
Condition0%0/3
$self->{"client_side_cache"} //= "Cache::LRU"->new("size", $self->client_side_cache_size)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"client_side_cache"} //= "Cache::LRU"->new("size", $self->client_side_cache_size)
$self->{"client_side_cache"} "Cache::LRU"->new("size", $self->client_side_cache_size)
Truth table0%0/3
A //= B
A= $self->{"client_side_cache"}B= "Cache::LRU"->new("size", $self->client_side_cache_size)
ABresult
1X1
011
000
384 size => $self->client_side_cache_size,
385 );
386 }
387  
388 0 ▶sub client_side_cache_enabled { defined shift->{client_side_cache_size} }
Subroutine client_side_cache_enabled: not called CC=1 SCAR=6.9
Pod undocumented
389 0 ▶sub client_side_cache_size { shift->{client_side_cache_size} }
Subroutine client_side_cache_size: not called CC=1 SCAR=6.9
Pod undocumented
390  
391 0 ▶around get => async sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
392 0 my ($code, $self, $k) = @_;
393 0 my $use_cache = $self->client_side_cache_enabled;
394 0 ▶ if($use_cache) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_cache) 0 0 0
395 0 $log->tracef('Check cache for [%s]', $k);
396 0 my $v = $self->client_side_cache->get($k);
397 0 ▶ return $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 0 0
398 0 $log->tracef('Key [%s] was not cached', $k);
399 }
400 0 my $v = await $self->$code($k);
401 0 ▶ $self->client_side_cache->set($k => $v) if $use_cache;
Branch: 1 branch
BranchTrueFalseTotal
if $use_cache 0 0 0
402 0 return $v;
403 10 };
404  
405  
406 =head1 METHODS - Generic
407  
408 =head2 keys
409  
410 =cut
411  
412 sub keys : method {
413 0 ▶ my ($self, $match) = @_;
Subroutine keys: not called CC=2 SCAR=17.9
Pod documented
414 0 ▶ $match //= '*';
Condition0%0/2
$match //= "*"
l!l
00
MC/DC0%0/1
$match //= "*"
$match
Truth table0%0/2
A
A= $match
Aresult
11
00
415 0 return $self->next::method($match);
416 }
417  
418 =head2 watch_keyspace
419  
420 A convenience wrapper around the keyspace notifications API.
421  
422 Provides the necessary setup to establish a C<PSUBSCRIBE> subscription
423 on the C<__keyspace@*__> namespace, setting the configuration required
424 for this to start emitting events, and then calls C<$code> with each
425 event.
426  
427 Note that this will switch the connection into pubsub mode, so it will
428 no longer be available for any other activity.
429  
430 Resolves to a L<Ryu::Source> instance.
431  
432 =cut
433  
434 0 ▶async sub watch_keyspace {
Subroutine watch_keyspace: not called CC=4 SCAR=30.0
Pod documented
435 0 my ($self, $pattern, $code) = @_;
436 0 ▶ $pattern //= '*';
Condition0%0/2
$pattern //= "*"
l!l
00
MC/DC0%0/1
$pattern //= "*"
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
437 0 my $sub_name = '__keyspace@*__:' . $pattern;
438 0 ▶ $self->{have_notify} ||= await $self->config_set(
Condition0%0/3
$self->{"have_notify"} ||= XXX
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"have_notify"} ||= XXX
$self->{"have_notify"} XXX
Truth table0%0/3
A ||= B
A= $self->{"have_notify"}B= XXX
ABresult
1X1
011
000
439 'notify-keyspace-events', 'Kg$xe'
440 );
441 0 my $sub = await $self->psubscribe($sub_name);
442 0 my $ev = $sub->events;
443 $ev->each(sub {
444 0 ▶ my $message = $_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
445 0 $log->tracef('Keyspace notification for channel %s, type %s, payload %s', map $message->$_, qw(channel type payload));
446 0 my $k = $message->channel;
447 0 $k =~ s/^[^:]+://;
448 0 my $f = $code->($message->payload, $k);
449 0 ▶ $f->retain if blessed($f) and $f->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($f) and $f->isa("Future") 0 0 0
Condition0%0/3
builtin::blessed($f) and $f->isa("Future")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($f) and $f->isa("Future")
builtin::blessed($f) $f->isa("Future")
Truth table0%0/3
A and B
A= builtin::blessed($f)B= $f->isa("Future")
ABresult
0X0
100
111
450 0 ▶ }) if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 0 0 0
451 0 return $ev;
452 10 }
453  
454 =head2 endpoint
455  
456 The string describing the remote endpoint.
457  
458 =cut
459  
460 0 ▶sub endpoint { shift->{endpoint} }
Subroutine endpoint: not called CC=1 SCAR=6.9
Pod documented
461  
462 =head2 local_endpoint
463  
464 A string describing the local endpoint, usually C<host:port>.
465  
466 =cut
467  
468 0 ▶sub local_endpoint { shift->{local_endpoint} }
Subroutine local_endpoint: not called CC=1 SCAR=6.9
Pod documented
469  
470 =head2 connect
471  
472 Connects to the Redis server.
473  
474 Will use the L</configure>d parameters if available, but as a convenience
475 can be passed additional parameters which will then be applied as if you
476 had called L</configure> with those beforehand. This also means that they
477 will be preserved for subsequent L</connect> calls.
478  
479 =cut
480  
481 sub connect : method {
482 0 ▶ my ($self, %args) = @_;
Subroutine connect: not called CC=8 SCAR=42.8
Pod documented
483 0 ▶ $self->configure(%args) if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 0 0
484 0 my $uri = $self->uri->clone;
485 0 for (qw(host port)) {
486 0 ▶ $uri->$_($self->$_) if defined $self->$_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$_ 0 0 0
487 }
488 0 my $auth = $self->{auth};
489 0 ▶ $auth //= ($uri->userinfo =~ s{^[^:]*:}{}r) if defined $uri->userinfo;
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo 0 0 0
Condition0%0/3
$auth //= $uri->userinfo =~ s/^[^:]*://r
l!l&&r!l&&!r
000
MC/DC0%0/2
$auth //= $uri->userinfo =~ s/^[^:]*://r
$auth $uri->userinfo =~ s/^[^:]*://r
Truth table0%0/3
A //= B
A= $authB= $uri->userinfo =~ s/^[^:]*://r
ABresult
1X1
011
000
490 $self->{connection} //= $self->loop->connect(
491 service => $uri->port // 6379,
492 host => $uri->host,
493 socktype => 'stream',
494 )->then(sub {
495 0 ▶ my ($sock) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
496 0 $self->{endpoint} = join ':', $sock->peerhost, $sock->peerport;
497 0 $self->{local_endpoint} = join ':', $sock->sockhost, $sock->sockport;
498 0 my $proto = $self->protocol;
499 my $stream = IO::Async::Stream->new(
500 handle => $sock,
501 read_len => $self->stream_read_len,
502 write_len => $self->stream_write_len,
503 read_high_watermark => 8 * $self->stream_read_len,
504 read_low_watermark => 2 * $self->stream_read_len,
505 on_closed => $self->curry::weak::notify_close,
506 on_read => sub {
507 0 ▶ $proto->parse($_[1]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
508 0 0
509 }
510 0 );
511 0 $self->add_child($stream);
512 Scalar::Util::weaken(
513 0 $self->{stream} = $stream
514 );
515 0 ▶ return $self->auth($auth) if defined $auth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $auth 0 0 0
516 0 return Future->done;
517 0 ▶ })->on_fail(sub { delete $self->{connection} });
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/5
$self->{"connection"} //= $self->loop->connect("service", $uri->port // 6379, "host", $uri->host, "socktype", "stream")->then(sub { my($sock) = @_; $self->{"endpoint"} = join(":", $sock->peerhost, $sock->peerport); $self->{"local_endpoint"} = join(":", $sock->sockhost, $sock->sockport); my $proto = $self->protocol; my $stream = "IO::Async::Stream"->new("handle", $sock, "read_len", $self->stream_read_len, "write_len", $self->stream_write_len, "read_high_watermark", 8 * $self->stream_read_len, "read_low_watermark", 2 * $self->stream_read_len, "on_closed", $self->curry::weak::notify_close, "on_read", sub { $proto->parse($_[1]); 0; } ); $self->add_child($stream); builtin::weaken($self->{"stream"} = $stream); return $self->auth($auth) if defined $auth; return "Future"->done; } )->on_fail(sub { delete $self->{"connection"}; } )
l!l&&r!l&&!r
000
$uri->port // 6379
l!l
00
MC/DC0%0/2
$self->{"connection"} //= $self->loop->connect("service", $uri->port // 6379, "host", $uri->host, "socktype", "stream")->then(sub { my($sock) = @_; $self->{"endpoint"} = join(":", $sock->peerhost, $sock->peerport); $self->{"local_endpoint"} = join(":", $sock->sockhost, $sock->sockport); my $proto = $self->protocol; my $stream = "IO::Async::Stream"->new("handle", $sock, "read_len", $self->stream_read_len, "write_len", $self->stream_write_len, "read_high_watermark", 8 * $self->stream_read_len, "read_low_watermark", 2 * $self->stream_read_len, "on_closed", $self->curry::weak::notify_close, "on_read", sub { $proto->parse($_[1]); 0; } ); $self->add_child($stream); builtin::weaken($self->{"stream"} = $stream); return $self->auth($auth) if defined $auth; return "Future"->done; } )->on_fail(sub { delete $self->{"connection"}; } )
$self->{"connection"} $self->loop->connect("service", $uri->port // 6379, "host", $uri->host, "socktype", "stream")->then(sub { my($sock) = @_; $self->{"endpoint"} = join(":", $sock->peerhost, $sock->peerport); $self->{"local_endpoint"} = join(":", $sock->sockhost, $sock->sockport); my $proto = $self->protocol; my $stream = "IO::Async::Stream"->new("handle", $sock, "read_len", $self->stream_read_len, "write_len", $self->stream_write_len, "read_high_watermark", 8 * $self->stream_read_len, "read_low_watermark", 2 * $self->stream_read_len, "on_closed", $self->curry::weak::notify_close, "on_read", sub { $proto->parse($_[1]); 0; } ); $self->add_child($stream); builtin::weaken($self->{"stream"} = $stream); return $self->auth($auth) if defined $auth; return "Future"->done; } )->on_fail(sub { delete $self->{"connection"}; } )
MC/DC0%0/1
$uri->port // 6379
$uri->port
Truth table0%0/3
A //= B
A= $self->{"connection"}B= $self->loop->connect("service", $uri->port // 6379, "host", $uri->host, "socktype", "stream")->then(sub { my($sock) = @_; $self->{"endpoint"} = join(":", $sock->peerhost, $sock->peerport); $self->{"local_endpoint"} = join(":", $sock->sockhost, $sock->sockport); my $proto = $self->protocol; my $stream = "IO::Async::Stream"->new("handle", $sock, "read_len", $self->stream_read_len, "write_len", $self->stream_write_len, "read_high_watermark", 8 * $self->stream_read_len, "read_low_watermark", 2 * $self->stream_read_len, "on_closed", $self->curry::weak::notify_close, "on_read", sub { $proto->parse($_[1]); 0; } ); $self->add_child($stream); builtin::weaken($self->{"stream"} = $stream); return $self->auth($auth) if defined $auth; return "Future"->done; } )->on_fail(sub { delete $self->{"connection"}; } )
ABresult
1X1
011
000
Truth table0%0/2
A
A= $uri->port
Aresult
11
00
518 }
519  
520 =head2 connected
521  
522 Establishes a connection if needed, otherwise returns an immediately-available
523 L<Future> instance.
524  
525 =cut
526  
527 sub connected {
528 0 ▶ my ($self) = @_;
Subroutine connected: not called CC=2 SCAR=17.9
Pod documented
529 0 ▶ return $self->{connection} if $self->{connection};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"connection"} 0 0 0
530 0 $self->connect;
531 }
532  
533 =head2 on_message
534  
535 Called for each incoming message.
536  
537 Passes off the work to L</handle_pubsub_message> or the next queue
538 item, depending on whether we're dealing with subscriptions at the moment.
539  
540 =cut
541  
542 sub on_message {
543 0 ▶ my ($self, $data) = @_;
Subroutine on_message: not called CC=7 SCAR=40.3
Pod documented
544 0 local @{$log->{context}}{qw(redis_remote redis_local)} = ($self->endpoint, $self->local_endpoint);
545 0 $log->tracef('Incoming message: %s', $data);
546 0 ▶ return $self->handle_pubsub_message(@$data) if exists $self->{pubsub} and exists $SUBSCRIPTION_COMMANDS{uc $data->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"pubsub"} and exists $Net::Async::Redis::SUBSCRIPTION_COMMANDS{uc $data->[0]} 0 0 0
Condition0%0/3
exists $self->{"pubsub"} and exists $Net::Async::Redis::SUBSCRIPTION_COMMANDS{uc $data->[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"pubsub"} and exists $Net::Async::Redis::SUBSCRIPTION_COMMANDS{uc $data->[0]}
exists $self->{"pubsub"} exists $Net::Async::Redis::SUBSCRIPTION_COMMANDS{uc $data->[0]}
Truth table0%0/3
A and B
A= exists $self->{"pubsub"}B= exists $Net::Async::Redis::SUBSCRIPTION_COMMANDS{uc $data->[0]}
ABresult
0X0
100
111
547  
548 0 ▶ my $next = shift @{$self->{pending}} or die "No pending handler";
Branch: 1 branch
BranchTrueFalseTotal
my $next = shift @{$$self{"pending"};} or die "No pending handler" 0 0 0
549 0 ▶ $self->next_in_pipeline if @{$self->{awaiting_pipeline}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"awaiting_pipeline"};} 0 0 0
550 0 ▶ return if $next->[1]->is_cancelled;
Branch: 1 branch
BranchTrueFalseTotal
if $next->[1]->is_cancelled 0 0 0
551 # This shouldn't happen, preferably
552 0 ▶ $log->errorf("our [%s] entry is ready, original was [%s]??", $data, $next->[0]) if $next->[1]->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $next->[1]->is_ready 0 0 0
553 0 $next->[1]->done($data);
554 }
555  
556 sub next_in_pipeline {
557 0 ▶ my ($self) = @_;
Subroutine next_in_pipeline: not called CC=4 SCAR=30.0
Pod undocumented
558 0 my $depth = $self->pipeline_depth;
559 0 ▶ until($depth and $self->{pending}->@* >= $depth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($depth and @{$self->{"pending"}} >= $depth) 0 0 0
Condition0%0/3
$depth and @{$self->{"pending"}} >= $depth
!ll&&!rl&&r
000
MC/DC0%0/2
$depth and @{$self->{"pending"}} >= $depth
$depth @{$self->{"pending"}} >= $depth
Truth table0%0/3
A and B
A= $depthB= @{$self->{"pending"}} >= $depth
ABresult
0X0
100
111
560 0 ▶ return unless my $next = shift @{$self->{awaiting_pipeline}};
Branch: 1 branch
BranchTrueFalseTotal
unless my $next = shift @{$$self{"awaiting_pipeline"};} 0 0 0
561 0 $log->tracef("Have free space in pipeline, sending %s", $next->[0]);
562 0 push @{$self->{pending}}, $next;
563 0 my $data = $self->protocol->encode_from_client($next->[0]);
564 0 $self->stream->write($data);
565 }
566 }
567  
568 sub on_error_message {
569 0 ▶ my ($self, $data) = @_;
Subroutine on_error_message: not called CC=2 SCAR=17.9
Pod undocumented
570 0 local @{$log->{context}}{qw(redis_remote redis_local)} = ($self->endpoint, $self->local_endpoint);
571 0 $log->tracef('Incoming error message: %s', $data);
572  
573 0 ▶ my $next = shift @{$self->{pending}} or die "No pending handler";
Branch: 1 branch
BranchTrueFalseTotal
my $next = shift @{$$self{"pending"};} or die "No pending handler" 0 0 0
574 0 $next->[1]->fail($data);
575 }
576  
577 sub handle_pubsub_message {
578 0 ▶ my ($self, $type, @details) = @_;
Subroutine handle_pubsub_message: not called CC=14 SCAR=53.5
Pod undocumented
579 0 $type = lc $type;
580 0 ▶ if($type eq 'message') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "message") 0 0 0
581 0 my ($channel, $payload) = @details;
582 0 ▶ if(my $sub = $self->{subscription_channel}{$channel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->{'subscription_channel'}{$channel}) { } 0 0 0
583 0 my $msg = Net::Async::Redis::Subscription::Message->new(
584 type => $type,
585 channel => $channel,
586 payload => $payload,
587 redis => $self,
588 subscription => $sub
589 );
590 0 $sub->events->emit($msg);
591 } else {
592 0 $log->warnf('Have message for unknown channel [%s]', $channel);
593 }
594 0 ▶ $self->bus->invoke_event(message => [ $type, $channel, $payload ]) if exists $self->{bus};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"bus"} 0 0 0
595 0 return;
596 }
597 0 ▶ if($type eq 'pmessage') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "pmessage") 0 0 0
598 0 my ($pattern, $channel, $payload) = @details;
599 0 ▶ if(my $sub = $self->{subscription_pattern_channel}{$pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->{'subscription_pattern_channel'}{$pattern}) { } 0 0 0
600 0 my $msg = Net::Async::Redis::Subscription::Message->new(
601 type => $type,
602 pattern => $pattern,
603 channel => $channel,
604 payload => $payload,
605 redis => $self,
606 subscription => $sub
607 );
608 0 $sub->events->emit($msg);
609 } else {
610 0 $log->warnf('Have message for unknown channel [%s]', $channel);
611 }
612 0 ▶ $self->bus->invoke_event(message => [ $type, $channel, $payload ]) if exists $self->{bus};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"bus"} 0 0 0
613 0 return;
614 }
615  
616 0 my ($channel, $payload) = @details;
617 0 ▶ my $k = (substr $type, 0, 1) eq 'p' ? 'subscription_pattern_channel' : 'subscription_channel';
Branch: 1 branch
BranchTrueFalseTotal
substr($type, 0, 1) eq 'p' ? : 0 0 0
618 0 ▶ if($type =~ /unsubscribe$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /unsubscribe$/) { } 0 0 0
elsif ($type =~ /subscribe$/) { } 0 0 0
619 0 --$self->{pubsub};
620 0 ▶ if(my $sub = delete $self->{$k}{$channel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = delete $self->{$k}{$channel}) { } 0 0 0
621 0 $log->tracef('Removed subscription for [%s]', $channel);
622 } else {
623 0 $log->warnf('Have unsubscription for unknown channel [%s]', $channel);
624 }
625 } elsif($type =~ /subscribe$/) {
626 0 ▶ $log->tracef('Have %s subscription for [%s]', (exists $self->{$k}{$channel} ? 'existing' : 'new'), $channel);
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$k}{$channel} ? : 0 0 0
627 0 ++$self->{pubsub};
628 0 ▶ $self->{$k}{$channel} //= Net::Async::Redis::Subscription->new(
Condition0%0/3
$self->{$k}{$channel} //= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $channel)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$k}{$channel} //= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $channel)
$self->{$k}{$channel} "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $channel)
Truth table0%0/3
A //= B
A= $self->{$k}{$channel}B= "Net::Async::Redis::Subscription"->new("redis", $self, "channel", $channel)
ABresult
1X1
011
000
629 redis => $self,
630 channel => $channel
631 );
632 0 ▶ $self->{'pending_' . $k}{$channel}->done($payload) unless $self->{'pending_' . $k}{$channel}->is_done;
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{'pending_' . $k}{$channel}->is_done 0 0 0
633 } else {
634 0 $log->warnf('have unknown pubsub message type %s with channel %s payload %s', $type, $channel, $payload);
635 }
636 }
637  
638 =head2 stream
639  
640 Represents the L<IO::Async::Stream> instance for the active Redis connection.
641  
642 =cut
643  
644 0 ▶sub stream { shift->{stream} }
Subroutine stream: not called CC=1 SCAR=6.9
Pod documented
645  
646 =head2 pipeline_depth
647  
648 Number of requests awaiting responses before we start queuing.
649 This defaults to an arbitrary value of 100 requests.
650  
651 Note that this does not apply when in L<transaction|METHODS - Transactions> (C<MULTI>) mode.
652  
653 See L<https://redis.io/topics/pipelining> for more details on this concept.
654  
655 =cut
656  
657 0 ▶sub pipeline_depth { shift->{pipeline_depth} //= 100 }
Subroutine pipeline_depth: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"pipeline_depth"} //= 100
l!l
00
MC/DC0%0/1
+(shift())->{"pipeline_depth"} //= 100
+(shift())->{"pipeline_depth"}
Truth table0%0/2
A
A= +(shift())->{"pipeline_depth"}
Aresult
11
00
658  
659 =head1 METHODS - Deprecated
660  
661 This are still supported, but no longer recommended.
662  
663 =cut
664  
665 sub bus {
666 0 ▶ shift->{bus} //= do {
Subroutine bus: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
+(shift())->{"bus"} //= do { require Mixin::Event::Dispatch::Bus; "Mixin::Event::Dispatch::Bus"->VERSION(2); "Mixin::Event::Dispatch::Bus"->new }
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"bus"} //= do { require Mixin::Event::Dispatch::Bus; "Mixin::Event::Dispatch::Bus"->VERSION(2); "Mixin::Event::Dispatch::Bus"->new }
+(shift())->{"bus"} do { require Mixin::Event::Dispatch::Bus; "Mixin::Event::Dispatch::Bus"->VERSION(2); "Mixin::Event::Dispatch::Bus"->new }
Truth table0%0/3
A //= B
A= +(shift())->{"bus"}B= do { require Mixin::Event::Dispatch::Bus; "Mixin::Event::Dispatch::Bus"->VERSION(2); "Mixin::Event::Dispatch::Bus"->new }
ABresult
1X1
011
000
667 0 require Mixin::Event::Dispatch::Bus;
668 0 Mixin::Event::Dispatch::Bus->VERSION(2.000);
669 0 Mixin::Event::Dispatch::Bus->new
670 }
671 }
672  
673 =head1 METHODS - Internal
674  
675 =cut
676  
677 =head2 notify_close
678  
679 Called when the socket is closed.
680  
681 =cut
682  
683 sub notify_close {
684 0 ▶ my ($self) = @_;
Subroutine notify_close: not called CC=6 SCAR=37.4
Pod documented
685 # If we think we have an existing connection, it needs removing:
686 # there's no guarantee that it's in a usable state.
687 0 ▶ if(my $stream = delete $self->{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stream = delete $self->{"stream"}) 0 0 0
688 0 $stream->close_now;
689 }
690  
691 # Also clear our connection future so that the next request is triggered appropriately
692 0 delete $self->{connection};
693 # Clear out anything in the pending queue - we normally wouldn't expect anything to
694 # have ready status here, but no sense failing on a failure. Note that we aren't
695 # filtering out the list via grep because some of these Futures may be interdependent.
696 0 ▶ !$_->[1]->is_ready && $_->[1]->fail('Server connection is no longer active', redis => 'disconnected') for splice @{$self->{pending}};
Branch: 1 branch
BranchTrueFalseTotal
$_->[1]->is_ready or $_->[1]->fail("Server connection is no longer active", "redis", "disconnected") 0 0 0
697  
698 # Subscriptions also need clearing up
699 0 $_->cancel for values %{$self->{subscription_channel}};
700 0 $self->{subscription_channel} = {};
701 0 $_->cancel for values %{$self->{subscription_pattern_channel}};
702 0 $self->{subscription_pattern_channel} = {};
703  
704 0 $self->maybe_invoke_event(disconnect => );
705 }
706  
707 =head2 command_label
708  
709 Generate a label for the given command list.
710  
711 =cut
712  
713 sub command_label {
714 0 ▶ my ($self, @cmd) = @_;
Subroutine command_label: not called CC=2 SCAR=17.9
Pod documented
715 0 ▶ return join ' ', @cmd if $cmd[0] eq 'KEYS';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd[0] eq "KEYS" 0 0 0
716 0 return $cmd[0];
717 }
718  
719 sub execute_command {
720 0 ▶ my ($self, @cmd) = @_;
Subroutine execute_command: not called CC=8 SCAR=42.8
Pod undocumented
721  
722 # First, the rules: pubsub or plain
723 0 my $is_sub_command = exists $SUBSCRIPTION_COMMANDS{$cmd[0]};
724 return Future->fail(
725 'Currently in pubsub mode, cannot send regular commands until unsubscribed',
726 redis =>
727 0 0 + (keys %{$self->{subscription_channel}}),
728 0 0 + (keys %{$self->{subscription_pattern_channel}})
729 0 ▶ ) if exists $self->{pubsub} and not exists $ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"pubsub"} and not exists $Net::Async::Redis::ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]} 0 0 0
Condition0%0/3
exists $self->{"pubsub"} and not exists $Net::Async::Redis::ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"pubsub"} and not exists $Net::Async::Redis::ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]}
exists $self->{"pubsub"} not exists $Net::Async::Redis::ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]}
Truth table0%0/3
A and not(B)
A= exists $self->{"pubsub"}B= not exists $Net::Async::Redis::ALLOWED_SUBSCRIPTION_COMMANDS{$cmd[0]}
ABresult
0X0
100
111
730  
731 0 my $f = $self->loop->new_future->set_label($self->command_label(@cmd));
732 0 ▶ $log->tracef("Will have to wait for %d MULTI tx", 0 + @{$self->{pending_multi}}) unless $self->{_is_multi};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_is_multi"} 0 0 0
733 my $code = sub {
734 0 ▶ local @{$log->{context}}{qw(redis_remote redis_local)} = ($self->endpoint, $self->local_endpoint);
Subroutine __ANON__: not called CC=4 SCAR=30.0
735 0 my $cmd = join ' ', @cmd;
736 0 $log->tracef('Outgoing [%s]', $cmd);
737 0 my $depth = $self->pipeline_depth;
738 0 $log->tracef("Pipeline depth now %d/%d", 0 + @{$self->{pending}}, $depth);
739 0 ▶ if($depth && $self->{pending}->@* >= $depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth and @{$self->{"pending"}} >= $depth) 0 0 0
Condition0%0/3
$depth and @{$self->{"pending"}} >= $depth
!ll&&!rl&&r
000
MC/DC0%0/2
$depth and @{$self->{"pending"}} >= $depth
$depth @{$self->{"pending"}} >= $depth
Truth table0%0/3
A and B
A= $depthB= @{$self->{"pending"}} >= $depth
ABresult
0X0
100
111
740 0 $log->tracef("Pipeline full, deferring %s (%d others in that queue)", $cmd, 0 + @{$self->{awaiting_pipeline}});
741 0 push @{$self->{awaiting_pipeline}}, [ $cmd, $f ];
742 0 return $f;
743 }
744 0 my $data = $self->protocol->encode_from_client(@cmd);
745 0 ▶ return $self->stream->write($data)->on_ready($f) if $is_sub_command;
Branch: 1 branch
BranchTrueFalseTotal
if $is_sub_command 0 0 0
746  
747 # Void-context write allows IaStream to combine multiple writes on the same connection.
748 0 push @{$self->{pending}}, [ $cmd, $f ];
749 0 $self->stream->write($data);
750 0 return $f
751 0 };
752 0 ▶ return $code->()->retain if $self->{stream} and ($self->{is_multi} or 0 == @{$self->{pending_multi}});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stream"} and $self->{"is_multi"} || 0 == @{$self->{"pending_multi"};} 0 0 0
Condition0%0/6
$self->{"stream"} and $self->{"is_multi"} || 0 == @{$self->{"pending_multi"};}
!ll&&!rl&&r
000
$self->{"is_multi"} or 0 == @{$self->{"pending_multi"};}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"stream"} and $self->{"is_multi"} || 0 == @{$self->{"pending_multi"};}
$self->{"stream"} $self->{"is_multi"} 0 == @{$self->{"pending_multi"};}
Truth table0%0/4
A and B or C
A= $self->{"stream"}B= $self->{"is_multi"}C= 0 == @{$self->{"pending_multi"};}
ABCresult
0XX0
1000
11X1
1011
753 return (
754 $self->{_is_multi}
755 ? $self->connected
756 : Future->wait_all(
757 $self->connected,
758 0 ▶ @{$self->{pending_multi}}
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_is_multi'} ? : 0 0 0
759 )
760 )->then($code)
761 ->retain;
762 }
763  
764 sub ryu {
765 0 ▶ my ($self) = @_;
Subroutine ryu: not called CC=2 SCAR=17.9
Pod undocumented
766 0 ▶ $self->{ryu} ||= do {
Condition0%0/3
$self->{"ryu"} ||= do { $self->add_child(my $ryu = "Ryu::Async"->new); $ryu }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ryu"} ||= do { $self->add_child(my $ryu = "Ryu::Async"->new); $ryu }
$self->{"ryu"} do { $self->add_child(my $ryu = "Ryu::Async"->new); $ryu }
Truth table0%0/3
A ||= B
A= $self->{"ryu"}B= do { $self->add_child(my $ryu = "Ryu::Async"->new); $ryu }
ABresult
1X1
011
000
767 0 $self->add_child(
768 my $ryu = Ryu::Async->new
769 );
770 0 $ryu
771 }
772 }
773  
774 sub future {
775 0 ▶ my ($self) = @_;
Subroutine future: not called CC=1 SCAR=6.9
Pod undocumented
776 0 return $self->loop->new_future(@_);
777 }
778  
779 sub protocol {
780 0 ▶ my ($self) = @_;
Subroutine protocol: not called CC=2 SCAR=17.9
Pod undocumented
781 0 ▶ $self->{protocol} ||= do {
Condition0%0/3
$self->{"protocol"} ||= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message, "error", $self->curry::weak::on_error_message) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"protocol"} ||= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message, "error", $self->curry::weak::on_error_message) }
$self->{"protocol"} do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message, "error", $self->curry::weak::on_error_message) }
Truth table0%0/3
A ||= B
A= $self->{"protocol"}B= do { require Net::Async::Redis::Protocol; "Net::Async::Redis::Protocol"->new("handler", $self->curry::weak::on_message, "error", $self->curry::weak::on_error_message) }
ABresult
1X1
011
000
782 0 require Net::Async::Redis::Protocol;
783 0 Net::Async::Redis::Protocol->new(
784 handler => $self->curry::weak::on_message,
785 error => $self->curry::weak::on_error_message,
786 )
787 };
788 }
789  
790 0 ▶sub host { shift->{host} }
Subroutine host: not called CC=1 SCAR=6.9
Pod documented
791 0 ▶sub port { shift->{port} }
Subroutine port: not called CC=1 SCAR=6.9
Pod documented
792 0 ▶sub uri { shift->{uri} //= URI->new('redis://localhost') }
Subroutine uri: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/3
+(shift())->{"uri"} //= "URI"->new("redis://localhost")
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"uri"} //= "URI"->new("redis://localhost")
+(shift())->{"uri"} "URI"->new("redis://localhost")
Truth table0%0/3
A //= B
A= +(shift())->{"uri"}B= "URI"->new("redis://localhost")
ABresult
1X1
011
000
793  
794 =head2 stream_read_len
795  
796 Defines the buffer size when reading from a Redis connection.
797  
798 Defaults to 1MB, reduce this if you're dealing with a lot of connections and
799 want to minimise memory usage. Alternatively, if you're reading large amounts
800 of data and spend too much time in needless C<epoll_wait> calls, try a larger
801 value.
802  
803 =cut
804  
805 0 ▶sub stream_read_len { shift->{stream_read_len} //= 1048576 }
Subroutine stream_read_len: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"stream_read_len"} //= 1048576
l!l
00
MC/DC0%0/1
+(shift())->{"stream_read_len"} //= 1048576
+(shift())->{"stream_read_len"}
Truth table0%0/2
A
A= +(shift())->{"stream_read_len"}
Aresult
11
00
806  
807 =head2 stream_write_len
808  
809 The buffer size when writing to Redis connections, in bytes. Defaults to 1MB.
810  
811 See L</stream_read_len>.
812  
813 =cut
814  
815 0 ▶sub stream_write_len { shift->{stream_read_len} //= 1048576 }
Subroutine stream_write_len: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"stream_read_len"} //= 1048576
l!l
00
MC/DC0%0/1
+(shift())->{"stream_read_len"} //= 1048576
+(shift())->{"stream_read_len"}
Truth table0%0/2
A
A= +(shift())->{"stream_read_len"}
Aresult
11
00
816  
817 sub configure {
818 0 ▶ my ($self, %args) = @_;
Subroutine configure: not called CC=13 SCAR=52.0
Pod documented
819 0 ▶ $self->{pending_multi} //= [];
Condition0%0/2
$self->{"pending_multi"} //= []
l!l
00
MC/DC0%0/1
$self->{"pending_multi"} //= []
$self->{"pending_multi"}
Truth table0%0/2
A
A= $self->{"pending_multi"}
Aresult
11
00
820 0 ▶ $self->{pending} //= [];
Condition0%0/2
$self->{"pending"} //= []
l!l
00
MC/DC0%0/1
$self->{"pending"} //= []
$self->{"pending"}
Truth table0%0/2
A
A= $self->{"pending"}
Aresult
11
00
821 0 ▶ $self->{awaiting_pipeline} //= [];
Condition0%0/2
$self->{"awaiting_pipeline"} //= []
l!l
00
MC/DC0%0/1
$self->{"awaiting_pipeline"} //= []
$self->{"awaiting_pipeline"}
Truth table0%0/2
A
A= $self->{"awaiting_pipeline"}
Aresult
11
00
822 0 for (qw(
823 host
824 port
825 auth
826 uri
827 pipeline_depth
828 stream_read_len
829 stream_write_len
830 on_disconnect
831 )) {
832 0 ▶ $self->{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 0 0 0
833 }
834 0 ▶ if(exists $args{client_side_cache_size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"client_side_cache_size"}) 0 0 0
835 0 $self->{client_side_cache_size} = delete $args{client_side_cache_size};
836 0 delete $self->{client_side_cache};
837 0 ▶ if($self->loop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->loop) 0 0 0
838 0 ▶ $self->remove_child(delete $self->{client_side_connection}) if $self->{client_side_connection};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"client_side_connection"} 0 0 0
839 0 $self->client_side_connection->retain;
840 }
841 }
842 0 ▶ my $uri = $self->{uri} = URI->new($self->{uri}) unless ref $self->uri;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->uri 0 0 0
843 0 ▶ if($uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) 0 0 0
844 0 ▶ $self->{host} //= $uri->host;
Condition0%0/3
$self->{"host"} //= $uri->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"host"} //= $uri->host
$self->{"host"} $uri->host
Truth table0%0/3
A //= B
A= $self->{"host"}B= $uri->host
ABresult
1X1
011
000
845 0 ▶ $self->{port} //= $uri->port;
Condition0%0/3
$self->{"port"} //= $uri->port
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"port"} //= $uri->port
$self->{"port"} $uri->port
Truth table0%0/3
A //= B
A= $self->{"port"}B= $uri->port
ABresult
1X1
011
000
846 }
847 0 $self->next::method(%args)
848 }
849  
850 sub _add_to_loop {
851 0 ▶ my ($self, $loop) = @_;
Subroutine _add_to_loop: not called CC=2 SCAR=17.9
852 0 delete $self->{client_side_connection};
853 0 ▶ $self->client_side_connection->retain if $self->client_side_cache_size;
Branch: 1 branch
BranchTrueFalseTotal
if $self->client_side_cache_size 0 0 0
854 }
855  
856 10 1;
857  
858 __END__
« Redis/Server/Database.pm ↑ Summary Redis/Multi.pm »