Protocol::Redis(3)
π» Protocol::Redis β the perl man page, but make it a group chat π
okay so bestie, this is the manual page for Protocol::Redis(3) β a User Contributed Perl Documentation page, section 3, and it's genuinely iconic for anyone doing Redis stuff in Perl.β¨
πΈ NAME πΈ
Protocol::Redis β a Redis protocol parser/encoder with asynchronous capabilities. yes, both jobs, one module, main character energy. π
β¨ SYNOPSIS β¨
use Protocol::Redis;
my $redis = Protocol::Redis->new(api => 1);
$redis->parse("+foo\r\n");
# get parsed message
my $message = $redis->get_message;
print "parsed message: ", $message->{data}, "\n";
# asynchronous parsing interface
$redis->on_message(sub {
my ($redis, $message) = @_;
print "parsed message: ", $message->{data}, "\n";
});
# parse pipelined message
$redis->parse("+bar\r\n-error\r\n");
# create message
print "Get key message:\n",
$redis->encode({type => '*', data => [
{type => '$', data => 'string'},
{type => '+', data => 'OK'}
]});
like, look at it. parse, get, callback, encode. the whole cozy little lifecycle. π«Ά
π¦ DESCRIPTION π¦
It's a Redis protocol parser/encoder β with asynchronous capabilities AND support for pipelining (the docs point you at http://redis.io/topics/pipelining). So yeah. It parses. It encodes. It's async. It pipelines. Obsessed. π
π APIv1 π
Protocol::Redis APIv1 uses "Unified Request Protocol" (http://redis.io/topics/protocol) for message encoding/parsing, and supports all the methods listed below. Client libraries should specify the API version during Protocol::Redis construction. β that's not a vibe suggestion, that's a please do this π
π new
my $redis = Protocol::Redis->new(api => 1);
Constructs a Protocol::Redis object with support for a specific API version. If the API version you specified isn't supported, the constructor should raise an exception β so don't come crying when it does, bestie, it literally warned you. π Client libraries should always specify the API version.
π parse
$redis->parse("*2\r\n$4ping\r\n\r\n");
Parses a Redis protocol chunk. that's it. that's the whole job. π
π get_message
while (my $message = $redis->get_message) {
...
}
Gets a parsed message, or undef. Lowkey the undef is how the loop knows to stop, so slay. π₯
π on_message
$redis->on_message(sub {
my ($redis, $message) = @_;
}
Calls the callback on each parsed message. async queen behavior tbqh. π§ (and yes, the code block above is exactly how it appears in the original β keeping it verbatim, no cap)
π encode
my $string = $redis->encode({type => '+', data => 'test'});
$string = $redis->encode(
{type => '*', data => [
{type => '$', data => 'test'}]});
Encodes data into a redis message. the other half of the parser/encoder duo. they're a package deal. π
π api
my $api_version = $redis->api;
Gets the API version. short, sweet, informative. β
π SUPPORT π
π¬ IRC
#redis on irc.perl.org β come hang, iykyk. the channel is right there, bestie. π
π¦ DEVELOPMENT π¦
π¦ Repository
http://github.com/und3f/protocol-redis
go look at the code. it's giving open source excellence. π π₯
πΈ AUTHOR πΈ
Serhii Zasenko, undef@cpan.org. the icon, the legend, the maintainer. π
π CREDITS π
In alphabetical order β and we respect alphabetical order in this house. β¨
- Dan Book (Grinnz)
- David Leadbeater (dgl)
- Jan Henning Thorsen (jhthorsen)
- Viacheslav Tykhanovskyi (vti)
- Yaroslav Korshak (yko)
π COPYRIGHT AND LICENSE π
Copyright (C) 2011-2024, Serhii Zasenko.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10. free software fr fr, go wild (within the license). π
okay so that's the whole page, nothing skipped, every flag-free method and URL intact. π«Ά
and finally, a cute little sign-off: this page came from perl v5.42.2, dated 2026-02-15. mwah. π
π¦ where this page comes from
- alpine 3.24: perl-protocol-redis-doc 1.0021-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms