The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojo::Redis2::Cursor - Cursor iterator for SCAN commands.

SYNOPSIS

  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;

DESCRIPTION

Mojo::Redis2::Cursor is an iterator object for SCAN family commands.

ATTRIBUTES

command

  $arrayref = $self->command;

Holds the command that is issued to the redis server, but without updated index information.

redis

  my $redus = $cursor->redis;
  $cursor->redis(Mojo::Redis2->new);

Redis object to work with.

METHODS

Mojo::Redis2::Cursor inherits all methods from Mojo::Base and implements the following new ones.

again

  $cursor->again;
  my $res = $cursor->again->all;

Reset cursor to start iterating from the beginning.

all

  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.

finished

  my $is_finished = $cursor->finished;

Indicate that full iteration had been made and no additional elements can be fetched.

hgetall

  my $hash = $redis2->scan->hgetall("redis.key");
  $hash = $cursor->hgetall("redis.key");
  $cursor->hgetall("redis.key" => sub {...});

Implements standard HGETALL command using HSCAN.

hkeys

  my $keys = $redis2->scan->hkeys("redis.key");
  $keys = $cursor->hkeys("redis.key");
  $cursor->hkeys("redis.key" => sub {...});

Implements standard HKEYS command using HSCAN.

keys

  my $keys = $redis2->scan->keys;
  $keys = $cursor->keys("*");
  $cursor->keys("*" => sub {
    my ($cur, $err, $keys) = @_;
    ...
  });

Implements standard KEYS command using SCAN.

new

  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.

next

  # 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.

  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.

smembers

  my $list = $redis2->scan->smembers("redis.key");
  $list = $cursor->smembers("redis.key");
  $cursor->smembers("redis.key" => sub {...});

Implements standard SMEMBERS command using SSCAN.

LINKS

http://redis.io/commands