AnyEvent-RipeRedis

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


- 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

README.md  view on Meta::CPAN

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 \] )

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN

  my $class  = shift;
  my %params = @_;

  my $self = bless {}, $class;

  $self->{host} = $params{host} || D_HOST;
  $self->{port} = $params{port} || D_PORT;
  $self->{password} = $params{password};
  $self->{database}
      = defined $params{database} ? $params{database} : D_DB_INDEX;
  $self->{utf8}          = exists $params{utf8} ? $params{utf8} : 1;
  $self->{lazy}          = $params{lazy};
  $self->{reconnect}     = exists $params{reconnect} ? $params{reconnect} : 1;
  $self->{handle_params} = $params{handle_params} || {};
  $self->{on_connect}    = $params{on_connect};
  $self->{on_disconnect} = $params{on_disconnect};

  $self->connection_timeout( $params{connection_timeout} );
  $self->read_timeout( $params{read_timeout} );
  $self->reconnect_interval( $params{reconnect_interval} );
  $self->on_error( $params{on_error} );

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN

        {
          croak qq{"$name" must be a positive number};
        }
        $self->{$name} = $seconds;
      }

      return $self->{$name};
    };
  }

  foreach my $name ( qw( utf8 reconnect on_connect on_disconnect ) ) {
    *{$name} = sub {
      my $self = shift;

      if (@_) {
        $self->{$name} = shift;
      }

      return $self->{$name};
    };
  }

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN

      my $reply;
      my $err_code;

      if ( defined $str_len ) {
        if ( length( $handle->{rbuf} ) < $str_len + EOL_LENGTH ) {
          return;
        }

        $reply = substr( $handle->{rbuf}, 0, $str_len, '' );
        substr( $handle->{rbuf}, 0, EOL_LENGTH, '' );
        if ( $self->{utf8} ) {
          utf8::decode($reply);
        }

        undef $str_len;
      }
      else {
        my $eol_pos = index( $handle->{rbuf}, EOL );

        if ( $eol_pos < 0 ) {
          return;
        }

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN

sub _push_write {
  my $self = shift;
  my $cmd  = shift;

  my $cmd_str = '';
  my @tokens  = ( @{ $cmd->{kwds} }, @{ $cmd->{args} } );
  foreach my $token (@tokens) {
    unless ( defined $token ) {
      $token = '';
    }
    elsif ( $self->{utf8} ) {
      utf8::encode($token);
    }
    $cmd_str .= '$' . length($token) . EOL . $token . EOL;
  }
  $cmd_str = '*' . scalar(@tokens) . EOL . $cmd_str;

  my $handle = $self->{_handle};

  if ( defined $self->{read_timeout}
    && !@{ $self->{_processing_queue} } )
  {

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN


=item 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 C<SELECT> command. The client remembers last selected
database after reconnection and switches to it automaticaly.

The default database index is C<0>.

=item 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.

=item connection_timeout => $fractional_seconds

Specifies connection timeout. If the client could not connect to the server
after specified timeout, the C<on_error> callback is called with the

lib/AnyEvent/RipeRedis.pm  view on Meta::CPAN

Gets current port of the client.

=head2 select( $index, [, $cb->( $reply, $err ) ] )

Selects the database by numeric index.

=head2 database()

Gets selected database index.

=head2 utf8( [ $boolean ] )

Enables or disables UTF-8 mode.

=head2 connection_timeout( [ $fractional_seconds ] )

Gets or sets the C<connection_timeout> of the client. The C<undef> value resets
the C<connection_timeout> to default value.

=head2 read_timeout( [ $fractional_seconds ] )

t/02-accessors.t  view on Meta::CPAN

  on_error => sub {
    return 3;
  },
);

can_ok( $redis, 'host' );
can_ok( $redis, 'port' );
can_ok( $redis, 'database' );
can_ok( $redis, 'connection_timeout' );
can_ok( $redis, 'read_timeout' );
can_ok( $redis, 'utf8' );
can_ok( $redis, 'reconnect' );
can_ok( $redis, 'reconnect_interval' );
can_ok( $redis, 'on_connect' );
can_ok( $redis, 'on_disconnect' );
can_ok( $redis, 'on_error' );

t_host($redis);
t_port($redis);
t_database($redis);
t_conn_timeout($redis);
t_read_timeout($redis);
t_reconnect($redis);
t_reconnect_interval($redis);
t_utf8($redis);
t_on_connect($redis);
t_on_disconnect($redis);
t_on_error($redis);


sub t_host {
  my $redis = shift;

  is( $redis->host, 'localhost', 'get host' );

t/02-accessors.t  view on Meta::CPAN

  $redis->reconnect_interval(undef);
  is( $redis->reconnect_interval, undef,
      q{disable "reconnect_interval"} );

  $redis->reconnect_interval(10);
  is( $redis->reconnect_interval, 10, q{set "reconnect_interval"} );

  return;
}

sub t_utf8 {
  my $redis = shift;

  is(  $redis->utf8, 1, q{get current UTF8 mode state} );

  $redis->utf8(undef);
  is( $redis->utf8, undef, q{disable UTF8 mode} );

  $redis->utf8(1);
  is( $redis->utf8, 1, q{enable UTF8 mode} );

  return;
}

sub t_on_connect {
  my $redis = shift;

  is( $redis->on_connect->(), 1, q{get "on_connect" callback} );

  $redis->on_connect(undef);

t/04-commands.t  view on Meta::CPAN

use 5.008000;
use strict;
use warnings;
use utf8;

use Test::More;
use AnyEvent::RipeRedis qw( :err_codes );
require 't/test_helper.pl';

my $server_info = run_redis_instance();
if ( !defined $server_info ) {
  plan skip_all => 'redis-server is required for this test';
}
plan tests => 33;

t/04-commands.t  view on Meta::CPAN

  },
);

ok( $T_CONNECTED, 'on_connect' );

t_status_reply($redis);
t_numeric_reply($redis);
t_bulk_reply($redis);
t_set_undef($redis);
t_get_undef($redis);
t_set_utf8_string($redis);
t_get_utf8_string($redis);
t_get_non_existent($redis);
t_mbulk_reply($redis);
t_mbulk_reply_empty_list($redis);
t_mbulk_reply_undef($redis);
t_nested_mbulk_reply($redis);
t_multiword_command($redis);
t_error_reply($redis);
t_default_on_error($redis);
t_error_after_exec($redis);
t_discard_method($redis);

t/04-commands.t  view on Meta::CPAN

        }
      );
    }
  );

  is( $t_reply, '', 'read undef; GET' );

  return;
}

sub t_set_utf8_string {
  my $redis = shift;

  my $t_reply;

  ev_loop(
    sub {
      my $cv = shift;

      $redis->set( 'ключ', 'Значение',
        sub {

t/04-commands.t  view on Meta::CPAN

        }
      );
    }
  );

  is( $t_reply, 'OK', 'write UTF-8 string; SET' );

  return;
}

sub t_get_utf8_string {
  my $redis = shift;

  my $t_reply;

  ev_loop(
    sub {
      my $cv = shift;

      $redis->set( 'ключ', 'Значение' );



( run in 0.545 second using v1.01-cache-2.11-cpan-49f99fa48dc )