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::XS->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 = $self->on(close => sub { my ($self) = @_; });
Emitted when the connection to the redis server gets closed.
connect
$cb = $self->on(connect => sub { my ($self) = @_; });
Emitted right after a connection is established to the Redis server, but after the AUTH and SELECT commands are queued.
error
$cb = $self->on(error => sub { my ($self, $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 = $self->on(response => sub { my ($self, $res) = @_; });
Emitted if "write_q" is not passed a Mojo::Promise as the last argument, or if the Redis server emits a message that is not handled.
ATTRIBUTES
encoding
$str = $self->encoding;
$self = $self->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 = $self->ioloop;
$self = $self->ioloop(Mojo::IOLoop->new);
Holds an instance of Mojo::IOLoop.
protocol
$protocol = $self->protocol;
$self = $self->protocol(Protocol::Redis::XS->new(api => 1));
Holds a protocol object, such as Protocol::Redis that is used to generate and parse Redis messages.
url
$url = $self->url;
$self = $self->url(Mojo::URL->new->host("/tmp/redis.sock")->path("/5"));
$self = $self->url("redis://localhost:6379/1");
METHODS
disconnect
$self = $self->disconnect;
Used to disconnect from the Redis server.
is_connected
$bool = $self->is_connected;
True if a connection to the Redis server is established.
write_p
$promise = $self->write_p($command => @args);
Will write a command to the Redis server and establish a connection if not already connected and returns a Mojo::Promise. The arguments will be passed on to "write_q".
write_q
$self = $self->write_q(@command => @args, Mojo::Promise->new);
$self = $self->write_q(@command => @args, undef);
Will enqueue a Redis command and either resolve/reject the Mojo::Promise or emit a "error" or "message" event when the Redis server responds.
This method is EXPERIMENTAL and currently meant for internal use.