Mojo::Redis2::Cursor - Cursor iterator for SCAN commands.
use Mojo::Redis2; use Mojo::Redis2::Cursor; my $cursor = Mojo::Redis2::Cursor->new(redis => Mojo::Redis2->new) ->command(["SCAN", 0, MATCH => "namespace*"]); # blocking while (my $r = $cursor->next) { say join "\n", @$r } # or non-blocking use feature "current_sub"; $cursor->next( sub { my ($cur, $err, $r) = @_; say join "\n", @$r; return Mojo::IOLoop->stop unless $cur->next(__SUB__); } ); Mojo::IOLoop->start;
Mojo::Redis2::Cursor is an iterator object for SCAN family commands.
SCAN
$arrayref = $self->command;
Holds the command that is issued to the redis server, but without updated index information.
my $redus = $cursor->redis; $cursor->redis(Mojo::Redis2->new);
Redis object to work with.
Mojo::Redis2::Cursor inherits all methods from Mojo::Base and implements the following new ones.
$cursor->again; my $res = $cursor->again->all;
Reset cursor to start iterating from the beginning.
my $keys = $cursor->all(COUNT => 5); $cursor->all(sub { my ($cur, $err, $res) = @_; });
Repeatedly call "next" to fetch all matching elements. Optional arguments will be passed along.
In case of error will return all data fetched so far.
my $is_finished = $cursor->finished;
Indicate that full iteration had been made and no additional elements can be fetched.
my $hash = $redis2->scan->hgetall("redis.key"); $hash = $cursor->hgetall("redis.key"); $cursor->hgetall("redis.key" => sub {...});
Implements standard HGETALL command using HSCAN.
HGETALL
HSCAN
my $keys = $redis2->scan->hkeys("redis.key"); $keys = $cursor->hkeys("redis.key"); $cursor->hkeys("redis.key" => sub {...});
Implements standard HKEYS command using HSCAN.
HKEYS
my $keys = $redis2->scan->keys; $keys = $cursor->keys("*"); $cursor->keys("*" => sub { my ($cur, $err, $keys) = @_; ... });
Implements standard KEYS command using SCAN.
KEYS
my $cursor = Mojo::Redis2::Cursor->new( command => ["SCAN", 0, MATCH => "namespace*"]); $cursor = Mojo::Redis2::Cursor->new( command => [ZSCAN => "redis.key", 0, COUNT => 15]);
Object constructor. Follows same semantics as Redis command.
# blocking my $res = $cursor->next; # non-blocking $cursor->next(sub { my ($cur, $err, $res) = @_; ... })
Issue next SCAN family command with cursor value from previous iteration. If last argument is coderef, will made a non-blocking call. In blocking mode returns arrayref with fetched elements. If no more items available, will return undef, for both blocking and non-blocking, without calling callback.
undef
my $res = $cursor->next(MATCH => "namespace*"); $cursor->next(COUNT => 100, sub { ... });
Accepts the same optional arguments as original Redis command, which will replace old values and will be used for this and next iterations.
my $list = $redis2->scan->smembers("redis.key"); $list = $cursor->smembers("redis.key"); $cursor->smembers("redis.key" => sub {...});
Implements standard SMEMBERS command using SSCAN.
SMEMBERS
SSCAN
http://redis.io/commands
To install Mojo::Redis2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Redis2
CPAN shell
perl -MCPAN -e shell install Mojo::Redis2
For more information on module installation, please visit the detailed CPAN module installation guide.