Mojo::R...::Cursor(3)

πŸ“¦ version 3.29, in alpine 3.24

πŸ’– NAME πŸ’–

Mojo::Redis::Cursor β€” the lil iterator bestie that walks you through results from SCAN, SSCAN, HSCAN and ZSCAN ✨ (this is the Mojo::R...::Cursor(3) page, straight out of the User Contributed Perl Documentation, hiiii 🫢)


🌸 SYNOPSIS 🌸

use Mojo::Redis;
my $redis  = Mojo::Redis->new;
my $cursor = $redis->cursor(hkeys => 'redis:scan_test:hash');
my $keys   = $cursor->all;

okay so like, that's the whole vibe: make a cursor, grab everything, done πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

Mojo::Redis::Cursor hands you the methods for iterating over the results of the Redis commands SCAN, SSCAN, HSCAN and ZSCAN. Like, instead of yeeting the entire keyspace at your face, it goes chunk by chunk πŸ‘‘

wanna know more? <https://redis.io/commands/scan> is right there, iykyk ⭐


πŸŽ€ ATTRIBUTES πŸŽ€

✨ command ✨

$array_ref = $cursor->command;

This is the current command being used to pull data out of Redis. It needs to be set in the constructor β€” but ngl, reading it back might not reflect the value you put in. it's giving "glow-up on assignment" πŸ’€ Examples:

$r->new(command => [hgetall => "foo*"]);
# $r->command == [hscan => "foo*", 0]

$r->new(command => [SSCAN => "foo*"])
# $r->command == [SSCAN => "foo*", 0]

Also, calling "next" will change the value of "command". Obsessed with the chaos, honestly. Example:

$r->new(command => ["keys"]);
# $r->command == [scan => 0]
$r->next;
# $r->command == [scan => 42]

🐚 connection 🐚

$conn   = $cursor->connection;
$cursor = $cursor->connection(Mojo::Redis::Connection->new);

Holds a Mojo::Redis::Connection object. classic, iconic, does what it says 🫢

πŸ’œ finished πŸ’œ

$bool = $cursor->finished;

True after you call "all", or if "next" has already iterated the whole list of members. it's the "bestie i'm full" flag πŸ“

πŸ”₯ redis πŸ”₯

$conn   = $cursor->connection;
$cursor = $cursor->connection(Mojo::Redis::Connection->new);

Holds a Mojo::Redis object β€” that's the thing used to create the connections to talk with Redis. (and yeah, the synopsis above literally shows connection there, not me, we don't make the rules, we just report them πŸ™ˆ)


🧚 METHODS 🧚

πŸ’« again πŸ’«

$cursor->again;

Resets the cursor so "next" starts over from the top. rewatching the series from ep 1 energy 🌈

πŸ’– all πŸ’–

$res    = $cursor->all;
$cursor = $cursor->all(sub { my ($cursor, $res) = @_ });

Returns all the members. $res is an array ref of strings β€” except when you're using the command "hgetall". no gatekeeping, take 'em all πŸ‘‘

⭐ all_p ⭐

$promise = $cursor->all_p->then(sub { my $res = shift });

Same as "all" but it returns a Mojo::Promise. async bestie behavior fr fr πŸ¦‹

🌸 new 🌸

$cursor = Mojo::Redis::Cursor->new(command => [...], redis => Mojo::Redis->new);

Builds a brand new object. "command" and "redis" are required as input β€” don't skip them, she'll notice πŸ’…

Here are some examples of the differnet commands that are supported (yes, "differnet", we keep every single letter around here 😭):

# Custom cursor commands
$cursor = $cursor->cursor(hscan => 0, match => '*', count => 100);
$cursor = $cursor->cursor(scan  => 0, match => '*', count => 100);
$cursor = $cursor->cursor(sscan => 0, match => '*', count => 100);
$cursor = $cursor->cursor(zscan => 0, match => '*', count => 100);

# Convenient cursor commands
$cursor = $cursor->cursor(hgetall  => "some:hash:key");
$cursor = $cursor->cursor(hkeys    => "some:hash:key");
$cursor = $cursor->cursor(keys     => "some:key:pattern*");
$cursor = $cursor->cursor(smembers => "some:set:key");

The convenient commands are alternatives to "hgetall" in Mojo::Redis::Database, "hkeys" in Mojo::Redis::Database, "keys" in Mojo::Redis::Database and "smembers" in Mojo::Redis::Database. same energy, shorter commute ✨

πŸŽ€ next πŸŽ€

$res    = $cursor->next;
$cursor = $cursor->next(sub { my ($cursor, $err, $res) = @_ });

Returns a chunk of members. $res is an array ref of strings β€” except when you're using the command "hgetall". And heads up: $res will also be undef() when the cursor is exhausted, and "finished" will be true. so like, know when to stop scrolling πŸ’€

🫢 next_p 🫢

$promise = $cursor->next_p;

Same as "next" but returns a Mojo::Prmoise. (that spelling? not a typo i introduced β€” it's literally what's written here, keeping it exactly 🌟)


πŸ‘‘ SEE ALSO πŸ‘‘

Mojo::Redis.


✨ that's the whole page, no cap ✨ this cutie comes from perl v5.42.2, dated 2026-02-15, and yes it's the Mojo::R...::Cursor(3) page πŸŽ€ thanks for reading bestie, go iterate something πŸ’…πŸ’–

πŸ“¦ where this page comes from