Mojo::Redis::Cursor - Iterate the results from SCAN, SSCAN, HSCAN and ZSCAN
use Mojo::Redis; my $redis = Mojo::Redis->new; my $cursor = $redis->cursor(hkeys => 'redis:scan_test:hash'); my $keys = $cursor->all;
Mojo::Redis::Cursor provides methods for iterating over the result from the Redis commands SCAN, SSCAN, HSCAN and ZSCAN.
See https://redis.io/commands/scan for more information.
$array_ref = $self->command;
The current command used to get data from Redis. This need to be set in the constructor, but reading it out might not reflect the value put in. 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". Example:
$r->new(command => ["keys"]); # $r->command == [scan => 0] $r->next; # $r->command == [scan => 42]
$conn = $self->connection; $self = $self->connection(Mojo::Redis::Connection->new);
Holds a Mojo::Redis::Connection object.
$bool = $self->finished;
True after calling "all" or if "next" has iterated the whole list of members.
Holds a Mojo::Redis object used to create the connections to talk with Redis.
$self->again;
Used to reset the cursor and make "next" start over.
$res = $self->all; $self = $self->all(sub { my ($self, $res) = @_ });
Used to return all members. $res is an array ref of strings, except when using the command "hgetall".
$res
$promise = $self->all_p->then(sub { my $res = shift });
Same as "all" but returns a Mojo::Promise.
$self = Mojo::Redis::Cursor->new(command => [...], redis => Mojo::Redis->new);
Used to construct a new object. "command" and "redis" is required as input.
Here are some examples of the differnet commands that are supported:
# Custom cursor commands $cursor = $self->cursor(hscan => 0, match => '*', count => 100); $cursor = $self->cursor(scan => 0, match => '*', count => 100); $cursor = $self->cursor(sscan => 0, match => '*', count => 100); $cursor = $self->cursor(zscan => 0, match => '*', count => 100); # Convenient cursor commands $cursor = $self->cursor(hgetall => "some:hash:key"); $cursor = $self->cursor(hkeys => "some:hash:key"); $cursor = $self->cursor(keys => "some:key:pattern*"); $cursor = $self->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.
$res = $self->next; $self = $self->next(sub { my ($self, $err, $res) = @_ });
Used to return a chunk of members. $res is an array ref of strings, except when using the command "hgetall". $res will also be undef() when the cursor is exhausted and "finished" will be true.
undef()
$promise = $self->next_p;
Same as "next" but returns a Mojo::Prmoise.
Mojo::Redis.
To install Mojo::Redis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Redis
CPAN shell
perl -MCPAN -e shell install Mojo::Redis
For more information on module installation, please visit the detailed CPAN module installation guide.