Protocol::Redis(3)

πŸ“¦ version 1.0021, in alpine 3.24

πŸ’» 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 (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