Mojo::R...::Cursor(3)
π 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
- 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