AnyEvent-RipeRedis

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


# DESCRIPTION

AnyEvent::RipeRedis is flexible non-blocking Redis client. Supports
subscriptions, transactions and can automaticaly restore connection after
failure.

Requires Redis 1.2 or higher, and any supported event loop.

# CONSTRUCTOR

## new( %params )

    my $redis = AnyEvent::RipeRedis->new(
      host               => 'localhost',
      port               => 6379,
      password           => 'yourpass',
      database           => 7,
      connection_timeout => 5,
      read_timeout       => 5,
      lazy               => 1,
      reconnect_interval => 5,

      on_connect => sub {
        # handling...
      },

      on_disconnect => sub {
        # handling...
      },

      on_error => sub {
        my $err = shift;

        # error handling...
      },
    );

- host => $host

    Server hostname (default: 127.0.0.1)

- port => $port

    Server port (default: 6379)

- password => $password

    If the password is specified, the `AUTH` command is sent to the server
    after connection.

- database => $index

    Database index. If the index is specified, the client switches to the specified
    database after connection. You can also switch to another database after
    connection by using `SELECT` command. The client remembers last selected
    database after reconnection and switches to it automaticaly.

    The default database index is `0`.

- utf8 => $boolean

    If enabled, all strings will be converted to UTF-8 before sending to
    the server, and all results will be decoded from UTF-8.

    Enabled by default.

- connection\_timeout => $fractional\_seconds

    Specifies connection timeout. If the client could not connect to the server
    after specified timeout, the `on_error` callback is called with the
    `E_CANT_CONN` error. The timeout specifies in seconds and can contain a
    fractional part.

        connection_timeout => 10.5,

    By default the client use kernel's connection timeout.

- read\_timeout => $fractional\_seconds

    Specifies read timeout. If the client could not receive a reply from the server
    after specified timeout, the client close connection and call the `on_error`
    callback with the `E_READ_TIMEDOUT` error. The timeout is specifies in seconds
    and can contain a fractional part.

        read_timeout => 3.5,

    Not set by default.

- lazy => $boolean

    If enabled, the connection establishes at time when you will send the first
    command to the server. By default the connection establishes after calling of
    the `new` method.

    Disabled by default.

- reconnect => $boolean

    If the connection to the server was lost and the parameter `reconnect` is
    TRUE (default), the client will try to restore the connection when you execute
    next command. The client will try to reconnect only once and, if attempt fails,
    the error object is passed to command callback. If you need several attempts of
    the reconnection, you must retry a command from the callback as many times, as
    you need. Such behavior allows to control reconnection procedure.

    Enabled by default.

- reconnect\_interval => $fractional\_seconds

    If the parameter is specified, the client will try to reconnect only after
    this interval. Commands executed between reconnections will be queued.

        reconnect_interval => 5,

    Not set by default.

- handle\_params => \\%params

    Specifies [AnyEvent::Handle](https://metacpan.org/pod/AnyEvent::Handle) parameters.

README.md  view on Meta::CPAN


    Multiple keys request during rehashing of slot.

- E\_ASK

    Redirection required. For more information see:
    [http://redis.io/topics/cluster-spec](http://redis.io/topics/cluster-spec)

- E\_MOVED

    Redirection required. For more information see:
    [http://redis.io/topics/cluster-spec](http://redis.io/topics/cluster-spec)

- E\_CLUSTER\_DOWN

    The cluster is down or hash slot not served.

# DISCONNECTION

When the connection to the server is no longer needed you can close it in three
ways: call the method `disconnect()`, send the `QUIT` command or you can just
"forget" any references to an AnyEvent::RipeRedis object, but in this
case the client object is destroyed without calling any callbacks, including
the `on_disconnect` callback, to avoid an unexpected behavior.

## disconnect()

The method for synchronous disconnection. All uncompleted operations will be
aborted.

## quit( \[ $cb->( $reply, $err ) \] )

The method for asynchronous disconnection.

# OTHER METHODS

## info( \[ $section \] \[, $cb->( $reply, $err ) \] )

Gets and parses information and statistics about the server. The result
is passed to callback as a hash reference.

More information about `INFO` command can be found here:
[http://redis.io/commands/info](http://redis.io/commands/info)

## host()

Gets current host of the client.

## port()

Gets current port of the client.

## select( $index, \[, $cb->( $reply, $err ) \] )

Selects the database by numeric index.

## database()

Gets selected database index.

## utf8( \[ $boolean \] )

Enables or disables UTF-8 mode.

## connection\_timeout( \[ $fractional\_seconds \] )

Gets or sets the `connection_timeout` of the client. The `undef` value resets
the `connection_timeout` to default value.

## read\_timeout( \[ $fractional\_seconds \] )

Gets or sets the `read_timeout` of the client.

## reconnect( \[ $boolean \] )

Enables or disables reconnection mode of the client.

## reconnect\_interval( \[ $fractional\_seconds \] )

Gets or sets `reconnect_interval` of the client.

## on\_connect( \[ $callback \] )

Gets or sets the `on_connect` callback.

## on\_disconnect( \[ $callback \] )

Gets or sets the `on_disconnect` callback.

## on\_error( \[ $callback \] )

Gets or sets the `on_error` callback.

# SEE ALSO

[AnyEvent::RipeRedis::Cluster](https://metacpan.org/pod/AnyEvent::RipeRedis::Cluster), [AnyEvent](https://metacpan.org/pod/AnyEvent), [Redis::hiredis](https://metacpan.org/pod/Redis::hiredis), [Redis](https://metacpan.org/pod/Redis),
[RedisDB](https://metacpan.org/pod/RedisDB)

# AUTHOR

Eugene Ponizovsky, <ponizovsky@gmail.com>

Sponsored by SMS Online, <dev.opensource@sms-online.com>

## Special thanks

- Alexey Shrub
- Vadim Vlasov
- Konstantin Uvarin
- Ivan Kruglov

# COPYRIGHT AND LICENSE

Copyright (c) 2012-2017, Eugene Ponizovsky, SMS Online. All rights reserved.

This module is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.



( run in 0.713 second using v1.01-cache-2.11-cpan-97f6503c9c8 )