Mojo::R...nnection(3)

πŸ“¦ version 3.29, in alpine 3.24

πŸ¦‹ Mojo::Redis::Connection(3) β€” the lowkey low-level Redis connection baddie

okay so this is Mojo::Redis::Connection, straight out of the User Contributed Perl Documentation squad (that's the manual name, bestie, we're not copying the header line, we're folding it in like a cute little name tag πŸŽ€). It's a Perl thing, and it's giving very much "under the hood, don't touch unless you know what you're doing" energy.


✨ NAME ✨

Mojo::Redis::Connection β€” a low level connection class for talking to Redis πŸ’…


✨ SYNOPSIS ✨

here's the vibe, copy it exactly or it won't slay:

use Mojo::Redis::Connection;

my $conn = Mojo::Redis::Connection->new(
             ioloop   => Mojo::IOLoop->singleton,
             protocol => Protocol::Redis::Faster->new(api => 1),
             url      => Mojo::URL->new("redis://localhost"),
           );

$conn->write_p("GET some_key")->then(sub { print "some_key=$_[0]" })->wait;

look at that promise chain, it's literally iconic πŸ”₯


✨ DESCRIPTION ✨

Mojo::Redis::Connection is a low level driver for writing and reading data from a Redis server. fr fr that's the whole job.

🫢 real talk though: you probably want to use Mojo::Redis instead of this class. this one is the plumbing, not the pretty bathroom.

✨ EVENTS ✨

🌸 close

$cb = $conn->on(close => sub { my ($conn) = @_; });

Emitted when the connection to the redis server gets closed. bye bestie πŸ‘‹

🌸 connect

$cb = $conn->on(connect => sub { my ($conn) = @_; });

Emitted right after a connection is established to the Redis server β€” but after the AUTH and SELECT commands are queued. so like, connected but the paperwork is still in the mail πŸ’Œ

🌸 error

$cb = $conn->on(error => sub { my ($conn, $error) = @_; });

Emitted if there's a connection error or the Redis server emits an error, and there's not a promise to handle the message. it's giving "no one was there to catch it so the event handler caught it" 😭

🌸 response

$cb = $conn->on(response => sub { my ($conn, $res) = @_; });

Emitted when receiving a message from the Redis server. the server texted back πŸ’Œβœ¨


✨ ATTRIBUTES ✨

πŸŽ€ encoding

$str  = $conn->encoding;
$conn = $conn->encoding("UTF-8");

Holds the character encoding to use for data from/to Redis. Set it to undef to disable encoding/decoding data β€” full chaos mode, no conversion. Without an encoding set, Redis expects and returns bytes. See also "encoding" in Mojo::Redis. 🧚

πŸŽ€ ioloop

$loop = $conn->ioloop;
$conn = $conn->ioloop(Mojo::IOLoop->new);

Holds an instance of Mojo::IOLoop. the event loop babe, the beating heart of it all πŸ’“

πŸŽ€ protocol

$protocol = $conn->protocol;
$conn     = $conn->protocol(Protocol::Redis::XS->new(api => 1));

Holds a protocol object β€” such as Protocol::Redis::Faster β€” that's used to generate and parse Redis messages. it's the translator between you and the server, iykyk πŸ¦‹

πŸŽ€ url

$url  = $conn->url;
$conn = $conn->url(Mojo::URL->new->host("/tmp/redis.sock")->path("/5"));
$conn = $conn->url("redis://localhost:6379/1");

the address of your Redis server, bestie. note that it can be a unix socket path like /tmp/redis.sock with a database path like /5, or a normal redis:// URL with host, port and db number. πŸ’…


✨ METHODS ✨

🌈 disconnect

$conn = $conn->disconnect;

Used to disconnect from the Redis server. that's it, that's the method, we're leaving πŸšͺπŸ’¨

🌈 is_connected

$bool = $conn->is_connected;

True if a connection to the Redis server is established. vibe check: are we connected or not 🌸

🌈 write

$conn = $conn->write(@command_and_args);

Used to write a message to the redis server. Calling this method should result in either a "error" or "response" event β€” one or the other, no third option, periodt. πŸ’€

This is useful in the a

😭 not me β€” the original manpage literally cuts off there at "This is useful in the a". no cap, that's the whole sentence. we don't make up endings, we just report the lore as it was handed down: This is useful in the a

🌈 write_p

$promise = $conn->write_p(@command_and_args);

Will write a command to the Redis server and establish a connection if not already connected, and returns a Mojo::Promise. it handles the connecting for you, main character energy fr fr πŸ‘‘


✨ SEE ALSO ✨

  • Mojo::Redis ⭐ β€” the one you should probably actually be using, bestie

and that's the whole page, mwah πŸ’‹

sign-off time: this gorgeous little document is from perl v5.42.2, dated 2026-02-15, and it lives under the name Mojo::R...nnection(3) πŸŽ€βœ¨ go forth and connect responsibly πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from