AnyEvent-Redis-RipeRedis
view release on metacpan or search on metacpan
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
# error handling...
return;
}
print "$reply\n";
},
}
);
$redis->set( 'bar', 'string' );
$redis->get( 'bar',
{ on_done => sub {
my $reply = shift;
print "$reply\n";
},
on_error => sub {
my $err_msg = shift;
my $err_code = shift;
# error handling...
}
}
);
$redis->lrange( 'list', 0, -1,
{ on_done => sub {
my $reply = shift;
foreach my $val ( @{$reply} ) {
print "$val\n";
}
},
on_error => sub {
my $err_msg = shift;
my $err_code = shift;
# error handling...
},
}
);
=over
=item on_done => $cb->( [ $reply ] )
The C<on_done> callback is called when the current operation was completed
successfully.
=item on_error => $cb->( $err_msg, $err_code )
The C<on_error> callback is called when some error occurred.
=item on_reply => $cb->( [ $reply ] [, $err_msg, $err_code ] )
Since version 1.300 of the client you can specify single, C<on_reply> callback,
instead of two, C<on_done> and C<on_error> callbacks. The C<on_reply> callback
is called in both cases: when operation was completed successfully or when some
error occurred. In first case to callback is passed only reply data. In second
case to callback is passed three arguments: The C<undef> value or reply data
with error objects (see below), error message and error code.
=back
=head1 TRANSACTIONS
The detailed information abount the Redis transactions can be found here:
L<http://redis.io/topics/transactions>.
=head2 multi( [ $cb | \%cbs ] )
Marks the start of a transaction block. Subsequent commands will be queued for
atomic execution using C<EXEC>.
=head2 exec( [ $cb | \%cbs ] )
Executes all previously queued commands in a transaction and restores the
connection state to normal. When using C<WATCH>, C<EXEC> will execute commands
only if the watched keys were not modified.
If after execution of C<EXEC> command at least one operation fails, the
C<on_error> or C<on_reply> callback is called and in addition to error message
and error code to callback is passed reply data, which contain replies of
successful operations and error objects for each failed operation. To
C<on_error> callback reply data is passed in third argument and to C<on_reply>
callback in first argument. Error object is an instance of class
C<AnyEvent::Redis::RipeRedis::Error> and has two methods: C<message()> to get
error message and C<code()> to get error code.
$redis->multi();
$redis->set( 'foo', 'string' );
$redis->incr( 'foo' ); # causes an error
$redis->exec(
sub {
my $reply = shift;
if (@_) {
my $err_msg = shift;
my $err_code = shift;
if ( defined $reply ) {
foreach my $nested_reply ( @{$reply} ) {
if ( ref($nested_reply) eq 'AnyEvent::Redis::RipeRedis::Error' ) {
my $nested_err_msg = $nested_reply->message();
my $nested_err_code = $nested_reply->code();
# error handling...
}
}
return;
}
# error handling...
return;
}
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
Transaction discarded because of previous errors.
=back
Error codes available since Redis 2.8.
=over
=item E_NO_AUTH
Authentication required.
=item E_WRONG_TYPE
Operation against a key holding the wrong kind of value.
=item E_NO_REPLICAS
Not enough good slaves to write.
=item E_BUSY_KEY
Target key name already exists.
=back
Error codes available since Redis 3.0.
=over
=item E_CROSS_SLOT
Keys in request don't hash to the same slot.
=item E_TRY_AGAIN
Multiple keys request during rehashing of slot.
=item E_ASK
Redirection required. For more information see:
L<http://redis.io/topics/cluster-spec>
=item E_MOVED
Redirection required. For more information see:
L<http://redis.io/topics/cluster-spec>
=item E_CLUSTER_DOWN
The cluster is down or hash slot not served.
=back
=head1 DISCONNECTION
When the connection to the server is no longer needed you can close it in three
ways: call the method C<disconnect()>, send the C<QUIT> command or you can just
"forget" any references to an AnyEvent::Redis::RipeRedis object, but in this
case a client object is destroyed without calling any callbacks, including
the C<on_disconnect> callback, to avoid an unexpected behavior.
=head2 disconnect()
The method for synchronous disconnection. All uncompleted operations will be
aborted.
$redis->disconnect();
=head2 quit()
The method for asynchronous disconnection.
$redis->quit(
sub {
# handling...
}
);
=head1 OTHER METHODS
=head2 connection_timeout( [ $fractional_seconds ] )
Get or set the C<connection_timeout> of the client. The C<undef> value resets
the C<connection_timeout> to default value.
=head2 read_timeout( [ $fractional_seconds ] )
Get or set the C<read_timeout> of the client.
=head2 reconnect( [ $boolean ] )
Enables or disables reconnection mode of the client.
=head2 min_reconnect_interval( [ $fractional_seconds ] )
Get or set C<min_reconnect_interval> of the client.
=head2 encoding( [ $enc_name ] )
Get or set the current C<encoding> of the client.
=head2 on_connect( [ $callback ] )
Get or set the C<on_connect> callback.
=head2 on_disconnect( [ $callback ] )
Get or set the C<on_disconnect> callback.
=head2 on_connect_error( [ $callback ] )
Get or set the C<on_connect_error> callback.
=head2 on_error( [ $callback ] )
Get or set the C<on_error> callback.
=head2 selected_database()
( run in 0.835 second using v1.01-cache-2.11-cpan-96521ef73a4 )