AnyEvent::Hiredis - AnyEvent hiredis API
use AnyEvent::Hiredis; my $redis = AnyEvent::Hiredis->new( host => '127.0.0.1', port => 6379, ); $redis->command( [qw/SET foo bar/], sub { warn "SET!" } ); $redis->command( [qw/GET foo/], sub { my $value = shift } ); $redis->command( [qw/LPUSH listkey value/] ); $redis->command( [qw/LPOP listkey/], sub { my $value = shift } ); # errors $redis->command( [qw/SOMETHING WRONG/, sub { my $error = $_[1] } );
AnyEvent::Hiredis is an AnyEvent Redis API that uses the hiredis C client library (https://github.com/antirez/hiredis).
AnyEvent::Hiredis
One reason to consider AnyEvent::Hiredis over its pure Perl counterpart AnyEvent::Redis is performance. Here's a head to head comparison of the two modules running on general purpose hardware:
AnyEvent::Redis
Rate ae_redis ae_hiredis AnyEvent::Redis 7590/s -- -89% AnyEvent::Hiredis 69400/s 814% --
Rate here is the number of set operations per second achieved by each module. See bin/compare.pl for details.
bin/compare.pl
my $redis = AnyEvent::Hiredis->new; # 127.0.0.1:6379 my $redis = AnyEvent::Hiredis->new(server => '192.168.0.1', port => '6379');
command takes an array ref representing a Redis command and a callback. When the command has completed the callback is executed and passed the result or error.
command
$redis->command( ['SET', $key, 'foo'], sub { my ($result, $error) = @_; $result; # 'OK' }); $redis->command( ['GET', $key], sub { my ($result, $error) = @_; $result; # 'foo' });
If the Redis server replies with an error then $result will be undef and $error will contain the Redis error string. Otherwise $error will be undef.
$result
undef
$error
http://github.com/wjackson/anyevent-hiredis
Whitney Jackson
Jonathan Rockway
Redis, Hiredis::Async, AnyEvent::Redis
To install AnyEvent::Hiredis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Hiredis
CPAN shell
perl -MCPAN -e shell install AnyEvent::Hiredis
For more information on module installation, please visit the detailed CPAN module installation guide.