view release on metacpan or search on metacpan
- POD edited.
1.111 Fri Oct 27 15:30:25 MSK 2012
- Minor changes in POD.
- Slight improvement in unit test.
- Minor internal changes.
1.110 Fri Oct 26 18:08:20 MSK 2012
- FEATURE: Added constructor parameter 'database'.
- FEATURE: Added constructor parameter 'lazy'.
- BUGFIX: Fixed reconnect error, which has been occurred if password was not
been required.
- Changes in POD.
1.109 Fri Oct 20 01:54:40 MSK 2012
- Changes in POD.
1.108 Fri Oct 20 01:28:40 MSK 2012
- Changes in POD.
1.107 Fri Oct 19 18:31:40 MSK 2012
examples/eval.pl view on Meta::CPAN
use warnings;
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
my $cv = AE::cv();
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => 6379,
password => 'redis_pass',
on_connect => sub {
print "Connected to Redis server\n";
},
on_disconnect => sub {
print "Disconnected from Redis server\n";
},
);
examples/generic.pl view on Meta::CPAN
use warnings;
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
my $cv = AE::cv();
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => 6379,
password => 'redis_pass',
on_connect => sub {
print "Connected to Redis server\n";
},
on_disconnect => sub {
print "Disconnected from Redis server\n";
},
);
examples/subs.pl view on Meta::CPAN
use warnings;
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
my $cv = AE::cv();
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => 6379,
password => 'redis_pass',
on_connect => sub {
print "Connected to Redis server\n";
},
on_disconnect => sub {
print "Disconnected from Redis server\n";
},
);
examples/unix_socket.pl view on Meta::CPAN
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
my $cv = AE::cv();
my $redis;
$redis = AnyEvent::Redis::RipeRedis->new(
host => 'unix/',
port => '/var/run/redis/redis.sock',
password => 'redis_pass',
connection_timeout => 5,
read_timeout => 5,
min_reconnect_interval => 5,
on_connect => sub {
print "Connected to Redis server\n";
},
on_disconnect => sub {
print "Disconnected from Redis server\n";
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
# Constructor
sub new {
my $proto = shift;
my %params = @_;
my $self = ref( $proto ) ? $proto : bless {}, $proto;
$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->{reconnect} = exists $params{reconnect} ? $params{reconnect} : 1;
$self->{on_connect} = $params{on_connect};
$self->{on_disconnect} = $params{on_disconnect};
$self->{on_connect_error} = $params{on_connect_error};
$self->encoding( $params{encoding} );
$self->connection_timeout( $params{connection_timeout} );
$self->read_timeout( $params{read_timeout} );
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
}
sub _get_on_connect {
my $self = shift;
weaken( $self );
return sub {
$self->{_connected} = 1;
unless ( defined $self->{password} ) {
$self->{_auth_st} = S_IS_DONE;
}
if ( $self->{database} == 0 ) {
$self->{_select_db_st} = S_IS_DONE;
}
if ( $self->{_auth_st} == S_NEED_PERFORM ) {
$self->_auth();
}
elsif ( $self->{_select_db_st} == S_NEED_PERFORM ) {
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
sub _auth {
my $self = shift;
weaken( $self );
$self->{_auth_st} = S_IN_PROGRESS;
$self->_push_write(
{ kwd => 'auth',
args => [ $self->{password} ],
on_done => sub {
$self->{_auth_st} = S_IS_DONE;
if ( $self->{_select_db_st} == S_NEED_PERFORM ) {
$self->_select_db();
}
else {
$self->{_ready_to_write} = 1;
$self->_flush_input_queue();
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
=head1 SYNOPSIS
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
my $cv = AE::cv();
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => 6379,
password => 'yourpass',
);
$redis->incr( 'foo',
sub {
my $reply = shift;
if (@_) {
my $err_msg = shift;
my $err_code = shift;
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
Requires Redis 1.2 or higher, and any supported event loop.
=head1 CONSTRUCTOR
=head2 new( %params )
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => 6379,
password => 'yourpass',
database => 7,
lazy => 1,
connection_timeout => 5,
read_timeout => 5,
reconnect => 1,
min_reconnect_interval => 5,
encoding => 'utf8',
on_connect => sub {
# handling...
lib/AnyEvent/Redis/RipeRedis.pm view on Meta::CPAN
=over
=item host => $host
Server hostname (default: 127.0.0.1)
=item port => $port
Server port (default: 6379)
=item password => $password
If the password is specified, the C<AUTH> command is sent to the server
after connection.
=item database => $index
Database index. If the index is specified, the client is switched 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.
The default database index is C<0>.
t/01-accessors.t view on Meta::CPAN
use 5.008000;
use strict;
use warnings;
use lib 't/tlib';
use Test::More tests => 37;
use AnyEvent::Redis::RipeRedis qw( :err_codes );
my $REDIS = AnyEvent::Redis::RipeRedis->new(
password => 'test',
connection_timeout => 10,
read_timeout => 5,
reconnect => 1,
min_reconnect_interval => 5,
encoding => 'utf8',
on_connect => sub {
return 1;
},
t/03-auth.t view on Meta::CPAN
my $SERVER_INFO = run_redis_instance(
requirepass => 'testpass',
);
if ( !defined $SERVER_INFO ) {
plan skip_all => 'redis-server is required for this test';
}
plan tests => 6;
t_successful_auth( $SERVER_INFO );
t_invalid_password( $SERVER_INFO );
sub t_successful_auth {
my $server_info = shift;
my $redis = AnyEvent::Redis::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => $server_info->{password},
);
can_ok( $redis, 'disconnect' );
my $t_reply;
ev_loop(
sub {
my $cv = shift;
t/03-auth.t view on Meta::CPAN
}
);
}
);
$redis->disconnect();
is( $t_reply, 'PONG', 'successful AUTH' );
}
sub t_invalid_password {
my $server_info = shift;
my $redis;
my $t_cli_err_msg;
my $t_cli_err_code;
my $t_cmd_err_msg;
my $t_cmd_err_code;
ev_loop(
sub {
my $cv = shift;
$redis = AnyEvent::Redis::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => 'invalid',
on_error => sub {
$t_cli_err_msg = shift;
$t_cli_err_code = shift;
$cv->send();
},
);
$redis->ping(
{ on_error => sub {
$t_cmd_err_msg = shift;
$t_cmd_err_code = shift;
},
}
);
}
);
$redis->disconnect();
my $t_name_prefix = 'invalid password';
like( $t_cmd_err_msg, qr/^Operation "ping" aborted:/,
"$t_name_prefix; command error message" );
is( $t_cmd_err_code, E_OPRN_ERROR, "$t_name_prefix; command error code" );
ok( defined $t_cli_err_msg, 'invalid password; client error message' );
is( $t_cli_err_code, E_OPRN_ERROR, "$t_name_prefix; client error code" );
return;
}
t/05-db-select.t view on Meta::CPAN
return;
}
sub t_auto_select_after_auth {
my $server_info = shift;
my $redis_db1 = AnyEvent::Redis::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => $server_info->{password},
database => 1,
);
my $redis_db2 = AnyEvent::Redis::RipeRedis->new(
host => $server_info->{host},
port => $server_info->{port},
password => $server_info->{password},
database => 2,
);
ev_loop(
sub {
my $cv = shift;
my $done_cnt = 0;
my $on_done_cb = sub {
if ( ++$done_cnt == 2 ) {
t/test_helper.pl view on Meta::CPAN
if ( !defined $redis_server ) {
return;
}
my %conn_info = $redis_server->connect_info();
return {
server => $redis_server,
host => $conn_info{host},
port => $conn_info{port},
password => $params{requirepass},
};
}
sub ev_loop {
my $sub = shift;
my $cv = AE::cv();
$sub->( $cv );