++ed by:
DBOOK KARJALA ARJONES BEROV ADAMJS

5 PAUSE users
4 non-PAUSE users.

Jan Henning Thorsen

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 = $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 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  = $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 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_p

  $promise = $conn->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

  $conn = $conn->write_q(@command => @args, Mojo::Promise->new);
  $conn = $conn->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.

SEE ALSO

Mojo::Redis