Mojo::R...nnection(3)
π¦ 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
- alpine 3.24: perl-mojo-redis-doc 3.29-r1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms