Redis - perl binding for Redis database
## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379 my $redis = Redis->new; my $redis = Redis->new(server => 'redis.example.com:8080'); ## Disable the automatic utf8 encoding => much more performance my $redis = Redis->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}); ## 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 $redis->wait_for_messages($timeout) while 1; ## ... until some condition $redis->wait_for_messages($timeout) while $keep_going; $redis->publish('topic_1', 'message');
Pure perl bindings for http://redis.io/
This version supports protocol 2.x (multi-bulk) or later of Redis available at https://github.com/antirez/redis/.
This documentation lists commands which are exercised in test suite, but additinal commands will work correctly since protocol specifies enough information to support almost all commands with same peace of code with a little help of C <AUTOLOAD> .
my $r = Redis->new; # $ENV{REDIS_SERVER} or 127.0.0.1:6379 my $r = Redis->new( server => '192.168.0.1:6379', debug => 0 ); my $r = Redis->new( server => '192.168.0.1:6379', encoding => undef );
$r->quit;
$r->ping || die "no server?";
$r->set( foo => 'bar' ); $r->setnx( foo => 42 );
my $value = $r->get( 'foo' );
my @values = $r->mget( 'foo', 'bar', 'baz' );
$r->incr('counter'); $r->incrby('tripplets', 3);
$r->decr('counter'); $r->decrby('tripplets', 3);
$r->exists( 'key' ) && print "got key!";
$r->del( 'key' ) || warn "key doesn't exist";
$r->type( 'key' ); # = string
my @keys = $r->keys( '*glob_pattern*' );
my $key = $r->randomkey;
my $ok = $r->rename( 'old-key', 'new-key', $new );
my $nr_keys = $r->dbsize;
See also Redis::List for tie interface.
$r->rpush( $key, $value );
$r->lpush( $key, $value );
$r->llen( $key );
my @list = $r->lrange( $key, $start, $end );
my $ok = $r->ltrim( $key, $start, $end );
$r->lindex( $key, $index );
$r->lset( $key, $index, $value );
my $modified_count = $r->lrem( $key, $count, $value );
my $value = $r->lpop( $key );
my $value = $r->rpop( $key );
$r->sadd( $key, $member );
$r->srem( $key, $member );
my $elements = $r->scard( $key );
$r->sismember( $key, $member );
$r->sinter( $key1, $key2, ... );
my $ok = $r->sinterstore( $dstkey, $key1, $key2, ... );
$r->select( $dbindex ); # 0 for new clients
$r->move( $key, $dbindex );
$r->flushdb;
$r->flushall;
$r->sort("key BY pattern LIMIT start end GET pattern ASC|DESC ALPHA');
$r->save;
$r->bgsave;
$r->lastsave;
$r->shutdown;
my $info_hash = $r->info;
Since Redis knows nothing about encoding, we are forcing utf-8 flag on all data received from Redis. This change is introduced in 1.2001 version. Please note that this encoding option severely degrades performance
You can disable this automatic encoding by passing an option to new: encoding => undef.
encoding => undef
This allows us to round-trip utf-8 encoded characters correctly, but might be problem if you push binary junk into Redis and expect to get it back without utf-8 flag turned on.
Pedro Melo, <melo@cpan.org>
<melo@cpan.org>
Original author and maintainer: Dobrica Pavlinusic, <dpavlin at rot13.org>
<dpavlin at rot13.org>
Please report any bugs or feature requests to bug-redis at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Redis. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-redis at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Redis perldoc Redis::List perldoc Redis::Hash
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Redis
CPAN Ratings
http://cpanratings.perl.org/d/Redis
Search CPAN
http://search.cpan.org/dist/Redis
The following persons contributed to this project (alphabetical order):
Copyright 2009-2010 Dobrica Pavlinusic, all rights reserved.
Copyright 2011 Pedro Melo, all rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Redis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Redis
CPAN shell
perl -MCPAN -e shell install Redis
For more information on module installation, please visit the detailed CPAN module installation guide.