AnyEvent-RipeRedis-Cluster

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

        { host => 'localhost', port => 7002 },
      ],
    );

    my $cv = AE::cv;

    $cluster->set( 'foo', 'bar',
      sub {
        my $err = $_[1];

        if ( defined $err ) {
          warn $err->message . "\n";
          $cv->send;

          return;
        }

        $cluster->get( 'foo',
          sub {
            my $reply = shift;
            my $err   = shift;

            if ( defined $err ) {
              warn $err->message . "\n";
              $cv->send;

              return;
            }

            print "$reply\n";
            $cv->send;
          }
        );
      }
    );

    $cv->recv;

# DESCRIPTION

AnyEvent::RipeRedis::Cluster is non-blocking Redis Cluster client built on top
of the [AnyEvent::RipeRedis](https://metacpan.org/pod/AnyEvent::RipeRedis).

Requires Redis 3.0 or higher, and any supported event loop.

For more information about Redis Cluster see here:

- [http://redis.io/topics/cluster-tutorial](http://redis.io/topics/cluster-tutorial)
- [http://redis.io/topics/cluster-spec](http://redis.io/topics/cluster-spec)

# CONSTRUCTOR

## new( %params )

    my $cluster = AnyEvent::RipeRedis::Cluster->new(
      startup_nodes => [
        { host => 'localhost', port => 7000 },
        { host => 'localhost', port => 7001 },
        { host => 'localhost', port => 7002 },
      ],
      password           => 'yourpass',
      connection_timeout => 5,
      read_timeout       => 5,
      refresh_interval   => 5,
      lazy               => 1,
      reconnect_interval => 5,

      on_node_connect => sub {
        my $host = shift;
        my $port = shift;

        # handling...
      },

      on_node_disconnect => sub {
        my $host = shift;
        my $port = shift;

        # handling...
      },

      on_node_error => sub {
        my $err = shift;
        my $host = shift;
        my $port = shift;

        # error handling...
      },

      on_error => sub {
        my $err = shift;

        # error handling...
      },
    );

- startup\_nodes => \\@nodes

    Specifies the list of startup nodes. Parameter should contain the array of
    hashes that contains addresses of some nodes in the cluster. Each hash should
    contain `host` and `port` elements. The client will try to connect to random
    node from the list to retrieve information about all cluster nodes and slots
    mapping. If the client could not connect to first selected node, it will try
    to connect to another random node from the list.

- password => $password

    If the password is specified, the `AUTH` command is sent to all nodes
    of the cluster after connection.

- allow\_slaves => $boolean

    If enabled, the client will try to send read-only commands to slave nodes.

    Disabled by default.

- utf8 => $boolean

    If enabled, all strings will be converted to UTF-8 before sending to nodes,
    and all results will be decoded from UTF-8.

    Enabled by default.

- connection\_timeout => $fractional\_seconds

    Specifies connection timeout. If the client could not connect to the node
    after specified timeout, the `on_node_error` callback is called with the
    `E_CANT_CONN` error. The timeout specifies in seconds and can contain a
    fractional part.

        connection_timeout => 10.5,

    By default the client use kernel's connection timeout.

- read\_timeout => $fractional\_seconds

    Specifies read timeout. If the client could not receive a reply from the node
    after specified timeout, the client close connection and call the
    `on_node_error` callback with the `E_READ_TIMEDOUT` error. The timeout is
    specifies in seconds and can contain a fractional part.

        read_timeout => 3.5,

    Not set by default.

- lazy => $boolean

    If enabled, the initial connection to the startup node establishes at time when
    you will send the first command to the cluster. By default the initial
    connection establishes after calling of the `new` method.

    Disabled by default.

- reconnect => $boolean

    If the connection to the node was lost and the parameter `reconnect` is
    TRUE (default), the client will try to restore the connection when you execute
    next command. The client will try to reconnect only once and, if attempt fails,
    the error object is passed to command callback. If you need several attempts of
    the reconnection, you must retry a command from the callback as many times, as
    you need. Such behavior allows to control reconnection procedure.

    Enabled by default.

- reconnect\_interval => $fractional\_seconds

    If the parameter is specified, the client will try to reconnect only after
    this interval. Commands executed between reconnections will be queued.



( run in 1.250 second using v1.01-cache-2.11-cpan-39bf76dae61 )