Mojo::Redis(3)
Mojo::Redis π β¨
okay bestie, welcome to the Mojo::Redis(3) era β this is the Perl manpage, and it's about a Redis driver that runs on top of Mojo::IOLoop. Buckle up, she's got range. π¦
πΈ NAME πΈ
Mojo::Redis β a Redis driver based on Mojo::IOLoop. iconic, no notes. π
β¨ SYNOPSIS β¨
π Blocking
the classic, the original, the "I'll just wait right here" energy:
use Mojo::Redis;
my $redis = Mojo::Redis->new;
$redis->db->set(foo => 42);
$redis->db->expire(foo => 600);
warn $redis->db->get('foo');
π¦ Promises
now we're asynchronous, we're booked and busy, we're thening:
$redis->db->get_p("mykey")->then(sub {
print "mykey=$_[0]\n";
})->catch(sub {
warn "Could not fetch mykey: $_[0]";
})->wait;
π₯ Pipelining
pipelining is literally baked into the API β you just yeet a whole bunch of commands in and then use "all" in Mojo::Promise to wait for all the responses. group-chat behavior honestly:
Mojo::Promise->all(
$db->set_p($key, 10),
$db->incrby_p($key, 9),
$db->incr_p($key),
$db->get_p($key),
$db->incr_p($key),
$db->get_p($key),
)->then(sub {
@res = map {@$_} @_;
})->wait;
π DESCRIPTION π
Mojo::Redis is a Redis driver that uses Mojo::IOLoop, which means it slots into the Mojolicious framework like it was always meant to be there. main character energy fr fr. β¨
It tries to mimic the same interface as Mojo::Pg, Mojo::mysql and Mojo::SQLite, but heads up β the methods for actually talking to the database do vary. π
β οΈ This module is in no way compatible with the 1.xx version of"Mojo::Redis", and this version also tries to fix a lot of the confusing methods in"Mojo::Redis2"related to pubsub. so likeβ¦ don't mix them, bestie, it's giving chaos.
π«Ά This module is currently EXPERIMENTAL, and bad design decisions will be fixed without warning. Please report at <https://github.com/jhthorsen/mojo-redis/issues> if you find this module useful, annoying, or if you simply find bugs. Feedback can also be sent to "jhthorsen@cpan.org". we love feedback, we eat it up.
π EVENTS π
π connection
$cb = $redis->on(connection => sub { my ($redis, $connection) = @_; });
Emitted when Mojo::Redis::Connection connects to the Redis. it's the "we're so back" moment. π
π ATTRIBUTES π
π encoding
$str = $redis->encoding;
$redis = $redis->encoding("UTF-8");
The value of this attribute gets passed on to "encoding" in Mojo::Redis::Connection whenever a new connection is created. so heads up: updating this attribute will not change any connection that's already in use. past connections are past, periodt. π
Default value is "UTF-8". β
π§ max_connections
$int = $redis->max_connections;
$redis = $redis->max_connections(5);
Maximum number of idle database handles to cache for future use β defaults to 5. (Default is subject to change, so likeβ¦ don't get too attached.) π
πΈ protocol_class
$str = $redis->protocol_class;
$redis = $redis->protocol_class("Protocol::Redis::XS");
Defaults to Protocol::Redis::XS if that optional module is available and at least version 0.06, otherwise it falls back to Protocol::Redis::Faster. she picks the bestie that's actually in the room. π«Ά
π¦ pubsub
$pubsub = $redis->pubsub;
Lazy builds an instance of Mojo::Redis::PubSub for this object β instead of returning a new instance like "db" does. different vibe, same icon. β¨
π url
$url = $redis->url;
$redis = $redis->url(Mojo::URL->new("redis://localhost/3"));
Holds an instance of Mojo::URL that describes how to connect to the Redis server. it's the map to the whole situation. πΊοΈ
π₯ METHODS π₯
π db
$db = $redis->db;
Returns an instance of Mojo::Redis::Database. go talk to her. π
β cache
$cache = $redis->cache(%attrs);
Returns an instance of Mojo::Redis::Cache. caching is self-care, ngl.
π cursor
$cursor = $redis->cursor(@command);
Returns an instance of Mojo::Redis::Cursor with "command" in Mojo::Redis::Cursor set to the arguments you passed. See "new" in Mojo::Redis::Cursor. for possible commands. iykyk. π¦
π new
$redis = Mojo::Redis->new("redis://localhost:6379/1");
$redis = Mojo::Redis->new(Mojo::URL->new->host("/tmp/redis.sock"));
$redis = Mojo::Redis->new(\%attrs);
$redis = Mojo::Redis->new(%attrs);
Object constructor. Can coerce a string into a Mojo::URL and set "url" if present. four ways to say hello, all valid. π
πΈ AUTHORS πΈ
- Jan Henning Thorsen β
"jhthorsen@cpan.org" - Dan Book β
"grinnz@grinnz.com"
the founding mothers, so to speak. π«Ά
π COPYRIGHT AND LICENSE π
Copyright (C) 2018, Jan Henning Thorsen.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. slay, legally. π
π that's the whole page, bestie! this wasMojo::Redis(3)fromperl v5.42.2, dated2026-02-15β no cap, go build something iconic with it. πβ¨π¦
π¦ 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