NAME

Mojo::Redis::Connection - Low level connection class for talking to Redis

SYNOPSIS

use Mojo::Redis::Connection;

my $conn = Mojo::Redis::Connection->new(
             ioloop   => Mojo::IOLoop->singleton,
             protocol => Protocol::Redis::Faster->new(api => 1),
             url      => Mojo::URL->new("redis://localhost"),
           );

$conn->write_p("GET some_key")->then(sub { print "some_key=$_[0]" })->wait;

DESCRIPTION

Mojo::Redis::Connection is a low level driver for writing and reading data from a Redis server.

You probably want to use Mojo::Redis instead of this class.

EVENTS

close

$cb = $conn->on(close => sub { my ($conn) = @_; });

Emitted when the connection to the redis server gets closed.

connect

$cb = $conn->on(connect => sub { my ($conn) = @_; });

Emitted right after a connection is established to the Redis server, but after the AUTH and SELECT commands are queued.

error

$cb = $conn->on(error => sub { my ($conn, $error) = @_; });

Emitted if there's a connection error or the Redis server emits an error, and there's not a promise to handle the message.

response

$cb = $conn->on(response => sub { my ($conn, $res) = @_; });

Emitted when receiving a message from the Redis server.

ATTRIBUTES

encoding

$str  = $conn->encoding;
$conn = $conn->encoding("UTF-8");

Holds the character encoding to use for data from/to Redis. Set to undef to disable encoding/decoding data. Without an encoding set, Redis expects and returns bytes. See also "encoding" in Mojo::Redis.

ioloop

$loop = $conn->ioloop;
$conn = $conn->ioloop(Mojo::IOLoop->new);

Holds an instance of Mojo::IOLoop.

protocol

$protocol = $conn->protocol;
$conn     = $conn->protocol(Protocol::Redis::XS->new(api => 1));

Holds a protocol object, such as Protocol::Redis::Faster that is used to generate and parse Redis messages.

url

$url  = $conn->url;
$conn = $conn->url(Mojo::URL->new->host("/tmp/redis.sock")->path("/5"));
$conn = $conn->url("redis://localhost:6379/1");

METHODS

disconnect

$conn = $conn->disconnect;

Used to disconnect from the Redis server.

is_connected

$bool = $conn->is_connected;

True if a connection to the Redis server is established.

write

$conn = $conn->write(@command_and_args);

Used to write a message to the redis server. Calling this method should result in either a "error" or "response" event.

This is useful in the a

write_p

$promise = $conn->write_p(@command_and_args);

Will write a command to the Redis server and establish a connection if not already connected and returns a Mojo::Promise.

SEE ALSO

Mojo::Redis