Mojo::Redis::Connection - Low level connection class for talking to Redis
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;
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.
$cb = $conn->on(close => sub { my ($conn) = @_; });
Emitted when the connection to the redis server gets closed.
$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.
$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.
$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.
$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.
undef
$loop = $conn->ioloop; $conn = $conn->ioloop(Mojo::IOLoop->new);
Holds an instance of Mojo::IOLoop.
$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 = $conn->url; $conn = $conn->url(Mojo::URL->new->host("/tmp/redis.sock")->path("/5")); $conn = $conn->url("redis://localhost:6379/1");
$conn = $conn->disconnect;
Used to disconnect from the Redis server.
$bool = $conn->is_connected;
True if a connection to the Redis server is established.
$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".
$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.
Mojo::Redis
To install Mojo::Redis, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Redis
CPAN shell
perl -MCPAN -e shell install Mojo::Redis
For more information on module installation, please visit the detailed CPAN module installation guide.