Mojo::Redis(3)

πŸ“¦ version 3.29, in alpine 3.24

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 (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 was Mojo::Redis(3) from perl v5.42.2, dated 2026-02-15 β€” no cap, go build something iconic with it. πŸ’–βœ¨πŸ¦‹
πŸ“¦ where this page comes from