NAME
MojoX::Redis - asynchronous Redis client for Mojolicious.
SYNOPSIS
use MojoX::Redis;
my $redis = MojoX::Redis->new(server => '127.0.0.1:6379');
# Execute some commands
$redis->execute(ping,
sub {
my ($redis, $res) = @_;
if ($res) {
print "Got result: ", $res->[0], "\n";
}
else {
print "Error: ", $redis->error, "\n";
}
})
# Cleanup connection
->execute(quit, sub { shift->stop })->start;
DESCRIPTION
MojoX::Redis is an asynchronous client to Redis for Mojo.
ATTRIBUTES
MojoX::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
.
METHODS
MojoX::Redis inherits all methods from l<Mojo::Base> and 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"]);
Execute specified command on Redis
server. If error occured during request $result will be set to undef, error string can be obtained with $redis->error.
error
$redis->execute("ping" => sub {
my ($redis, $result) = @_;
die $redis->error unless defined $result;
}
Returns error occured during command execution. Note that this method returns error code just from current command and can be used just in callback.
start
$redis->start;
Starts IOLoop. Shortcut for $redis->ioloop->start;
SEE ALSO
AUTHOR
Sergey Zasenko, undef@cpan.org
.
COPYRIGHT AND LICENSE
Copyright (C) 2010, Sergey Zasenko
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.