AnyEvent-Redis-RipeRedis
view release on metacpan or search on metacpan
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
is given.
When no patters are specified, the client is unsubscribed from all the
previously subscribed patterns. In this case, a message for every unsubscribed
pattern will be sent to the client.
$redis->punsubscribe( qw( foo_* bar_* ),
sub {
my $reply = shift;
if (@_) {
my $err_msg = shift;
my $err_code = shift;
# error handling...
return;
}
my $pattern = $reply->[0];
my $channels_num = $reply->[1];
# handling...
}
);
$redis->punsubscribe( qw( foo_* bar_* ),
{ on_done => sub {
my $pattern = shift;
my $channels_num = shift;
# handling...
},
}
);
=over
=item on_done => $cb->( $channel, $channels_num )
The C<on_done> callback is called on every specified pattern when the
unsubscription operation was completed successfully.
=item on_error => $cb->( $err_msg, $err_code )
The C<on_error> callback is called if the unsubscription operation fails.
=item on_reply => $cb->( [ $reply ] [, $err_msg, $err_code ] )
The C<on_reply> callback is called in both cases: when the unsubscription
operation was completed successfully or when unsubscription operation fails.
In first case C<on_reply> callback is called on every specified pattern.
Information about channel pattern and number of remaining subscriptions is
passed to callback in first argument as an array reference.
=back
=head1 CONNECTION VIA UNIX-SOCKET
Redis 2.2 and higher support connection via UNIX domain socket. To connect via
a UNIX-socket in the parameter C<host> you have to specify C<unix/>, and in
the parameter C<port> you have to specify the path to the socket.
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'unix/',
port => '/tmp/redis.sock',
);
=head1 LUA SCRIPTS EXECUTION
Redis 2.6 and higher support execution of Lua scripts on the server side.
To execute a Lua script you can send one of the commands C<EVAL> or C<EVALSHA>,
or use the special method C<eval_cached()>.
=head2 eval_cached( $script, $numkeys [, @keys ] [, @args ] [, $cb | \%cbs ] );
When you call the C<eval_cached()> method, the client first generate a SHA1
hash for a Lua script and cache it in memory. Then the client optimistically
send the C<EVALSHA> command under the hood. If the C<E_NO_SCRIPT> error will be
returned, the client send the C<EVAL> command.
If you call the C<eval_cached()> method with the same Lua script, client don not
generate a SHA1 hash for this script repeatedly, it gets a hash from the cache
instead.
$redis->eval_cached( 'return { KEYS[1], KEYS[2], ARGV[1], ARGV[2] }',
2, 'key1', 'key2', 'first', 'second',
sub {
my $reply = shift;
if (@_) {
my $err_msg = shift;
my $err_code = shift;
# error handling...
return;
}
foreach my $val ( @{$reply} ) {
print "$val\n";
}
}
);
Be care, passing a different Lua scripts to C<eval_cached()> method every time
cause memory leaks.
If Lua script returns multi-bulk reply with at least one error reply, 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 successful
replies and error objects for each error reply, as well as described for C<EXEC>
command.
$redis->eval_cached( "return { 'foo', redis.error_reply( 'Error.' ) }", 0,
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' ) {
( run in 0.811 second using v1.01-cache-2.11-cpan-39bf76dae61 )