# AUTHOR Ichinose Shogo # SYNOPSIS ## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379 my $redis = Redis::Fast->new; my $redis = Redis::Fast->new(server => 'redis.example.com:8080'); ## Set the connection name (requires Redis 2.6.9) my $redis = Redis::Fast->new( server => 'redis.example.com:8080', name => 'my_connection_name', ); my $generation = 0; my $redis = Redis::Fast->new( server => 'redis.example.com:8080', name => sub { "cache-$$-".++$generation }, ); ## Use UNIX domain socket my $redis = Redis::Fast->new(sock => '/path/to/socket'); ## Enable auto-reconnect ## Try to reconnect every 500ms up to 60 seconds until success ## Die if you can't after that my $redis = Redis::Fast->new(reconnect => 60); ## Try each 100ms upto 2 seconds (every is in milisecs) my $redis = Redis::Fast->new(reconnect => 2, every => 100); ## Disable the automatic utf8 encoding => much more performance ## !!!! This will be the default after 2.000, see ENCODING below my $redis = Redis::Fast->new(encoding => undef); ## Use all the regular Redis commands, they all accept a list of ## arguments ## See http://redis.io/commands for full list $redis->get('key'); $redis->set('key' => 'value'); $redis->sort('list', 'DESC'); $redis->sort(qw{list LIMIT 0 5 ALPHA DESC}); ## Add a coderef argument to run a command in the background $redis->sort(qw{list LIMIT 0 5 ALPHA DESC}, sub { my ($reply, $error) = @_; die "Oops, got an error: $error\n" if defined $error; print "$_\n" for @$reply; }); long_computation(); $redis->wait_all_responses; ## or $redis->wait_one_response(); ## Or run a large batch of commands in a pipeline my %hash = _get_large_batch_of_commands(); $redis->hset('h', $_, $hash{$_}, sub {}) for keys %hash; $redis->wait_all_responses; ## Publish/Subscribe $redis->subscribe( 'topic_1', 'topic_2', sub { my ($message, $topic, $subscribed_topic) = @_ ## $subscribed_topic can be different from topic if ## you use psubscribe() with wildcards } ); $redis->psubscribe('nasdaq.*', sub {...}); ## Blocks and waits for messages, calls subscribe() callbacks ## ... forever my $timeout = 10; $redis->wait_for_messages($timeout) while 1; ## ... until some condition my $keep_going = 1; ## other code will set to false to quit $redis->wait_for_messages($timeout) while $keep_going; $redis->publish('topic_1', 'message'); # DESCRIPTION `Redis::Fast` is a wrapper around Salvatore Sanfilippo's [hiredis](https://github.com/antirez/hiredis) C client. It is compatible with [Redis.pm](https://github.com/melo/perl-redis). This version supports protocol 2.x (multi-bulk) or later of Redis available at [https://github.com/antirez/redis/](https://github.com/antirez/redis/). # SEE ALSO - [Redis.pm](https://github.com/melo/perl-redis)