| 1 | package Net::Async::Redis::XS; | ||||||||||||||||||||
| 2 | # ABSTRACT: faster version of Net::Async::Redis | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.008'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 5 | ▶ | use parent qw(Net::Async::Redis); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | Net::Async::Redis::XS - like L<Net::Async::Redis> but faster | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | use feature qw(say); | ||||||||||||||||||||
| 18 | use Future::AsyncAwait; | ||||||||||||||||||||
| 19 | use IO::Async::Loop; | ||||||||||||||||||||
| 20 | use Net::Async::Redis::XS; | ||||||||||||||||||||
| 21 | my $loop = IO::Async::Loop->new; | ||||||||||||||||||||
| 22 | $loop->add(my $redis = Net::Async::Redis::XS); | ||||||||||||||||||||
| 23 | await $redis->connect; | ||||||||||||||||||||
| 24 | await $redis->set('some-key', 'some-value'); | ||||||||||||||||||||
| 25 | say await $redis->get('some-key'); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | This is a wrapper around L<Net::Async::Redis> with faster protocol parsing. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | It implements the L<Net::Async::Redis::Protocol> protocol code in XS for better performance, | ||||||||||||||||||||
| 32 | and will eventually be extended to optimise some other slow paths as well in future. | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | API and behaviour should be identical to L<Net::Async::Redis>, see there for instructions. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 5 | package Net::Async::Redis::Protocol::XS { | |||||||||||||||||||
| 39 | 5 | ▶ | use parent qw(Net::Async::Redis::Protocol); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | sub decode { | ||||||||||||||||||||
| 42 | 0 | ▶ | my ($self, $bytes) = @_; | ||||||||||||||||||
|
Subroutine
decode: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 43 | 0 | my @data = Net::Async::Redis::XS::decode_buffer($self, $$bytes); | |||||||||||||||||||
| 44 | 0 | $self->item($_) for @data; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 5 | ▶ | sub dl_load_flags { 1 } | ||||||||||||||||||
|
Subroutine
dl_load_flags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 5 | require DynaLoader; | |||||||||||||||||||
| 51 | 5 | __PACKAGE__->DynaLoader::bootstrap(__PACKAGE__->VERSION); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | sub wire_protocol { | ||||||||||||||||||||
| 54 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
wire_protocol: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 55 | 0 | ▶ | $self->{wire_protocol} ||= do { | ||||||||||||||||||
|
Condition0%0/3
$$self{"wire_protocol"} ||= do {
MC/DC0%0/2
$$self{"wire_protocol"} ||= do {
"Net::Async::Redis::Protocol::XS"->new("handler", $self->curry::weak::on_message, "pubsub", $self->curry::weak::handle_pubsub_message, "error", $self->curry::weak::on_error_message, "protocol", $$self{"protocol_level"} || "resp3")
}
$$self{"wire_protocol"}
do {
"Net::Async::Redis::Protocol::XS"->new("handler", $self->curry::weak::on_message, "pubsub", $self->curry::weak::handle_pubsub_message, "error", $self->curry::weak::on_error_message, "protocol", $$self{"protocol_level"} || "resp3")
}
Truth table0%0/3
A ||= B
A= $$self{"wire_protocol"}B= do {
"Net::Async::Redis::Protocol::XS"->new("handler", $self->curry::weak::on_message, "pubsub", $self->curry::weak::handle_pubsub_message, "error", $self->curry::weak::on_error_message, "protocol", $$self{"protocol_level"} || "resp3")
}
| |||||||||||||||||||||
| 56 | Net::Async::Redis::Protocol::XS->new( | ||||||||||||||||||||
| 57 | handler => $self->curry::weak::on_message, | ||||||||||||||||||||
| 58 | pubsub => $self->curry::weak::handle_pubsub_message, | ||||||||||||||||||||
| 59 | error => $self->curry::weak::on_error_message, | ||||||||||||||||||||
| 60 | 0 | ▶ | protocol => $self->{protocol_level} || 'resp3', | ||||||||||||||||||
|
Condition0%0/2
$$self{'protocol_level'} || 'resp3'
MC/DC0%0/1
$$self{'protocol_level'} || 'resp3'
$$self{'protocol_level'}
Truth table0%0/2
A
A= $$self{'protocol_level'}
| |||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 5 | 1; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =head1 AUTHOR | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | Tom Molesworth <TEAM@cpan.org> | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | with contributions from C<< PEVANS@cpan.org >>. | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =head1 LICENSE | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | Copyright Tom Molesworth 2022. Licensed under the same terms as Perl itself. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||