AnyEvent-RipeRedis-Cluster
view release on metacpan or search on metacpan
my $err = shift;
if ( defined $err ) {
my $err_msg = $err->message;
my $err_code = $err->code;
# error handling...
return;
}
print "$reply\n";
}
);
# TRANSACTIONS
To perform the transaction you must get the master node by the key using
`nodes` method and then execute all commands on this node. Nodes must be
discovered first.
$node = $cluster->nodes('foo');
$node->multi;
$node->set( '{foo}bar', "some\r\nstring" );
$node->set( '{foo}car', 42 );
$node->exec(
sub {
my $reply = shift;
my $err = shift;
if ( defined $err ) {
# error handling...
return;
}
# reply handling...
}
);
The detailed information about the Redis transactions can be found in
documentation on [AnyEvent::RipeRedis](https://metacpan.org/pod/AnyEvent::RipeRedis) and here:
[http://redis.io/topics/transactions](http://redis.io/topics/transactions).
# ERROR CODES
Every error object, passed to callback, contain error code, which can be used
for programmatic handling of errors. AnyEvent::RipeRedis::Cluster provides
constants for error codes. They can be imported and used in expressions.
use AnyEvent::RipeRedis::Cluster qw( :err_codes );
Full list of error codes see in documentation on [AnyEvent::RipeRedis](https://metacpan.org/pod/AnyEvent::RipeRedis).
# DISCONNECTION
When the connection to the cluster is no longer needed you can close it in two
ways: call the method `disconnect()` or just "forget" any references to an
AnyEvent::RipeRedis::Cluster object, but in this case the client object is
destroyed without calling any callbacks, including the `on_disconnect`
callback, to avoid an unexpected behavior.
## disconnect()
The method for disconnection. All uncompleted operations will be
aborted.
# OTHER METHODS
## nodes( \[ $key \] \[, $allow\_slaves \] )
Gets particular nodes of the cluster. Nodes must be discovered first. In scalar
context method returns the first node from the list.
Getting all master nodes of the cluster:
my @master_nodes = $cluster->nodes;
Getting all nodes of the cluster, including slave nodes:
my @nodes = $cluster->nodes( undef, 1 );
Getting master node by the key:
my $master_node = $cluster->nodes('foo');
Getting nodes by the key, including slave nodes:
my @nodes = $cluster->nodes( 'foo', 1 );
## refresh\_interval( \[ $fractional\_seconds \] )
Gets or sets the `refresh_interval` of the client. The `undef` value resets
the `refresh_interval` to default value.
## on\_error( \[ $callback \] )
Gets or sets the `on_error` callback.
# SERVICE FUNCTIONS
Service functions provided by AnyEvent::RipeRedis::Cluster can be imported.
use AnyEvent::RipeRedis::Cluster qw( crc16 hash_slot );
## crc16( $data )
Compute CRC16 for the specified data as defined in Redis Cluster specification.
## hash\_slot( $key );
Returns slot number by the key.
# SEE ALSO
[AnyEvent::RipeRedis](https://metacpan.org/pod/AnyEvent::RipeRedis)
# AUTHOR
Eugene Ponizovsky, <ponizovsky@gmail.com>
( run in 1.634 second using v1.01-cache-2.11-cpan-140bd7fdf52 )