NAME Mojo::Redis - asynchronous Redis client for Mojolicious. SYNOPSIS use Mojo::Redis; my $redis = Mojo::Redis->new(server => '127.0.0.1:6379'); # Execute some commands $redis->ping( sub { my ($redis, $res) = @_; if (defined $res) { print "Got result: ", $res->[0], "\n"; } } ); # Work with keys $redis->set(key => 'value'); $redis->get( key => sub { my ($redis, $res) = @_; print "Value of 'key' is $res\n"; } ); # Cleanup connection $redis->quit(sub { shift->ioloop->stop }); # Start IOLoop (in case it is not started yet) $redis->ioloop->start; Create new Mojo::IOLoop instance if you need to get blocked in a Mojolicious application. use Mojolicious::Lite; use Mojo::Redis; get '/' => sub { my $self = shift; my $redis = Mojo::Redis->new(ioloop => Mojo::IOLoop->new); my $value; $redis->set(foo => 'bar')->get( foo => sub { my ($redis, $result) = @_; $redis->quit->ioloop->stop; $value = $result->[0]; } )->ioloop->start; $self->render(text => qq(Foo value is "$value")); }; app->start; DESCRIPTION Mojo::Redis is an asynchronous client to Redis for Mojo. EVENTS error $redis->on(error => sub{ my($redis, $error) = @_; warn "[REDIS ERROR] $error\n"; }); Emitted if error occurred. Called before commands callbacks. close $redis->on(close => sub{ my($redis) = @_; warn "[REDIS DISCONNECT]\n"; }); Emitted when the connection to the server gets closed. ATTRIBUTES Mojo::Redis implements the following attributes. server my $server = $redis->server; $redis = $redis->server('127.0.0.1:6379'); "Redis" server connection string, defaults to '127.0.0.1:6379'. ioloop my $ioloop = $redis->ioloop; $redis = $redis->ioloop(Mojo::IOLoop->new); Loop object to use for io operations, by default a Mojo::IOLoop singleton object will be used. timeout my $timeout = $redis->timeout; $redis = $redis->timeout(100); Maximum amount of time in seconds a connection can be inactive before being dropped, defaults to 300. encoding my $encoding = $redis->encoding; $redis = $redis->encoding('UTF-8'); Encoding used for stored data, defaults to "UTF-8". protocol_redis use Protocol::Redis::XS; $redis->protocol_redis("Protocol::Redis::XS"); Protocol::Redis implementation' constructor for parsing. By default Protocol::Redis will be used. Parser library must support APIv1. Using Protocol::Redis::XS instead of default choice can speedup parsing. METHODS Mojo::Redis supports Redis' methods. $redis->set(key => 'value); $redis->get(key => sub { ... }); For more details take a look at "execute" method. Also Mojo::Redis implements the following ones. connect $redis = $redis->connect; Connect to "Redis" server. execute $redis = $redis->execute("ping" => sub { my ($redis, $result) = @_; # Process result }); $redis->execute(lrange => "test", 0, -1 => sub {...}); $redis->execute(set => test => "test_ok"); $redis->execute( [lrange => "test", 0, -1], [get => "test"], [hmset => foo => { one => 1, two => 2 }], sub { my($redis, $lrange, $get, $hmset) = @_; # ... }, ); Execute specified command on "Redis" server. If error occurred during request $result will be set to undef, error string can be obtained with the "error" event. REDIS METHODS subscribe It's possible to subscribe in two ways: $self = $redis->subscribe('foo','bar' => sub { my ($redis, $data) = @_; }); The above code will overtake the current connection (if any) and put this object into a pure subscribe mode. $sub = $redis->subscribe('foo','bar')->on(data => sub { my ($sub, $data) = @_; }); Opens up a new connection that subscribes to the given pubsub channels. Returns an instance of Mojo::Redis::Subscription. The existing $redis object can still be used to "get" data as expected. REDIS METHODS append auth bgrewriteaof bgsave blpop brpop brpoplpush config_get config_resetstat config_set connected dbsize debug_object debug_segfault decr decrby del discard disconnect echo exec exists expire expireat flushall flushdb get getbit getrange getset hdel hexists hget hgetall hincrby hkeys hlen hmget hmset hset hsetnx hvals incr incrby info keys lastsave lindex linsert llen lpop lpush lpushx lrange lrem lset ltrim mget monitor move mset msetnx multi persist ping protocol publish quit randomkey rename renamenx rpop rpoplpush rpush rpushx sadd save scard sdiff sdiffstore select set setbit setex setnx setrange shutdown sinter sinterstore sismember slaveof smembers smove sort spop srandmember srem strlen sunion sunionstore sync ttl type unwatch watch zadd zcard zcount zincrby zinterstore zrange zrangebyscore zrank zrem zremrangebyrank zremrangebyscore zrevrange zrevrangebyscore zrevrank zscore zunionstore SEE ALSO Protocol::Redis, Mojolicious, Mojo::IOLoop SUPPORT IRC #mojo on irc.perl.org DEVELOPMENT Repository https://github.com/und3f/mojox-redis AUTHOR Sergey Zasenko, "undef@cpan.org". Forked from MojoX::Redis and updated to new IOLoop API by Marcus Ramberg "mramberg@cpan.org". COPYRIGHT AND LICENSE Copyright (C) 2010-2011, Sergey Zasenko (C) 2012, Marcus Ramberg This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.