Skip to content

Commit fd3be56

Browse files
committed
Removed "on_connect_error" callback
1 parent c6ae56e commit fd3be56

File tree

3 files changed

+15
-116
lines changed

3 files changed

+15
-116
lines changed

lib/AnyEvent/RipeRedis.pm

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ sub new {
140140
$self->{handle_params} = $params{handle_params} || {};
141141
$self->{on_connect} = $params{on_connect};
142142
$self->{on_disconnect} = $params{on_disconnect};
143-
$self->{on_connect_error} = $params{on_connect_error};
144143

145144
$self->connection_timeout( $params{connection_timeout} );
146145
$self->read_timeout( $params{read_timeout} );
@@ -232,9 +231,7 @@ sub on_error {
232231
};
233232
}
234233

235-
foreach my $name ( qw( utf8 reconnect on_connect on_disconnect
236-
on_connect_error ) )
237-
{
234+
foreach my $name ( qw( utf8 reconnect on_connect on_disconnect ) ) {
238235
*{$name} = sub {
239236
my $self = shift;
240237

@@ -962,12 +959,7 @@ sub _abort {
962959
my $err_msg = $err->message;
963960
my $err_code = $err->code;
964961

965-
if ( defined $self->{on_connect_error} && $err_code == E_CANT_CONN ) {
966-
$self->{on_connect_error}->($err);
967-
}
968-
else {
969-
$self->{on_error}->($err);
970-
}
962+
$self->{on_error}->($err);
971963

972964
if ( %channels && $err_code != E_CONN_CLOSED_BY_CLIENT ) {
973965
foreach my $name ( keys %channels ) {
@@ -1124,12 +1116,6 @@ Requires Redis 1.2 or higher, and any supported event loop.
11241116
# handling...
11251117
},
11261118
1127-
on_connect_error => sub {
1128-
my $err = shift;
1129-
1130-
# error handling...
1131-
},
1132-
11331119
on_error => sub {
11341120
my $err = shift;
11351121
@@ -1171,9 +1157,9 @@ Enabled by default.
11711157
=item connection_timeout => $fractional_seconds
11721158
11731159
Specifies connection timeout. If the client could not connect to the server
1174-
after specified timeout, the C<on_connect_error> callback is called with the
1175-
C<E_CANT_CONN> error, or if it not specified, the C<on_error> callback is
1176-
called. The timeout specifies in seconds and can contain a fractional part.
1160+
after specified timeout, the C<on_error> callback is called with the
1161+
C<E_CANT_CONN> error. The timeout specifies in seconds and can contain a
1162+
fractional part.
11771163
11781164
connection_timeout => 10.5,
11791165
@@ -1244,18 +1230,10 @@ reason.
12441230
12451231
Not set by default.
12461232
1247-
=item on_connect_error => $cb->( $err )
1248-
1249-
The C<on_connect_error> callback is called, when the connection could not be
1250-
established. If this callback isn't specified, the C<on_error> callback is
1251-
called.
1252-
1253-
Not set by default.
1254-
12551233
=item on_error => $cb->( $err )
12561234
12571235
The C<on_error> callback is called when occurred an error, which was affected
1258-
on whole client (e. g. connection error or authentication error). Also the
1236+
on entire client (e. g. connection error or authentication error). Also the
12591237
C<on_error> callback is called on command errors if the command callback is not
12601238
specified. If the C<on_error> callback is not specified, the client just print
12611239
an error messages to C<STDERR>.
@@ -1859,10 +1837,6 @@ Get or set the C<on_connect> callback.
18591837
18601838
Get or set the C<on_disconnect> callback.
18611839
1862-
=head2 on_connect_error( [ $callback ] )
1863-
1864-
Get or set the C<on_connect_error> callback.
1865-
18661840
=head2 on_error( [ $callback ] )
18671841
18681842
Get or set the C<on_error> callback.

t/02-accessors.t

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use strict;
33
use warnings;
44

55
use lib 't/tlib';
6-
use Test::More tests => 41;
6+
use Test::More tests => 37;
77
use AnyEvent::RipeRedis qw( :err_codes );
88
use AnyEvent::RipeRedis::Error;
99

@@ -23,12 +23,8 @@ my $REDIS = AnyEvent::RipeRedis->new(
2323
return 2;
2424
},
2525

26-
on_connect_error => sub {
27-
return 3;
28-
},
29-
3026
on_error => sub {
31-
return 4;
27+
return 3;
3228
},
3329
);
3430

@@ -41,7 +37,6 @@ can_ok( $REDIS, 'utf8' );
4137
can_ok( $REDIS, 'reconnect' );
4238
can_ok( $REDIS, 'on_connect' );
4339
can_ok( $REDIS, 'on_disconnect' );
44-
can_ok( $REDIS, 'on_connect_error' );
4540
can_ok( $REDIS, 'on_error' );
4641

4742
t_host($REDIS);
@@ -54,7 +49,6 @@ t_min_reconnect_interval($REDIS);
5449
t_utf8($REDIS);
5550
t_on_connect($REDIS);
5651
t_on_disconnect($REDIS);
57-
t_on_connect_error($REDIS);
5852
t_on_error($REDIS);
5953

6054

@@ -203,31 +197,11 @@ sub t_on_disconnect {
203197
return;
204198
}
205199

206-
sub t_on_connect_error {
207-
my $redis = shift;
208-
209-
my $on_conn_error = $redis->on_connect_error;
210-
is( $on_conn_error->(), 3, q{get "on_connect_error" callback} );
211-
212-
$redis->on_connect_error(undef);
213-
is( $redis->on_connect_error, undef,
214-
q{disable "on_connect_error" callback} );
215-
216-
$redis->on_connect_error(
217-
sub {
218-
return 7;
219-
}
220-
);
221-
is( $redis->on_connect_error->(), 7, q{set "on_connect_error" callback} );
222-
223-
return;
224-
}
225-
226200
sub t_on_error {
227201
my $redis = shift;
228202

229203
my $on_error = $redis->on_error;
230-
is( $on_error->(), 4, q{get "on_error" callback} );
204+
is( $on_error->(), 3, q{get "on_error" callback} );
231205

232206
local %SIG;
233207
my $t_err;
@@ -245,11 +219,11 @@ sub t_on_error {
245219

246220
$redis->on_error(
247221
sub {
248-
return 8;
222+
return 4;
249223
}
250224
);
251225

252-
is( $redis->on_error->(), 8, q{set "on_error" callback} );
226+
is( $redis->on_error->(), 4, q{set "on_error" callback} );
253227

254228
return;
255229
}

t/09-conn-errors.t

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ use 5.008000;
22
use strict;
33
use warnings;
44

5-
use Test::More tests => 45;
5+
use Test::More tests => 40;
66
use AnyEvent::RipeRedis qw( :err_codes );
77
use Net::EmptyPort qw( empty_port );
88
use Scalar::Util qw( weaken );
99
require 't/test_helper.pl';
1010

11-
t_cant_connect_mth1();
12-
t_cant_connect_mth2();
13-
11+
t_cant_connect();
1412
t_no_connection();
1513
t_reconnection();
1614
t_read_timeout();
@@ -21,54 +19,7 @@ t_premature_conn_close_mth2();
2119
t_subscription_lost();
2220

2321

24-
sub t_cant_connect_mth1 {
25-
my $redis;
26-
my $port = empty_port();
27-
28-
my $t_cli_err;
29-
my $t_cmd_err;
30-
31-
AE::now_update();
32-
ev_loop(
33-
sub {
34-
my $cv = shift;
35-
36-
$redis = AnyEvent::RipeRedis->new(
37-
port => $port,
38-
connection_timeout => 3,
39-
reconnect => 0,
40-
41-
on_connect_error => sub {
42-
$t_cli_err = shift;
43-
},
44-
);
45-
46-
$redis->ping(
47-
sub {
48-
my $reply = shift;
49-
$t_cmd_err = shift;
50-
51-
$cv->send;
52-
}
53-
);
54-
},
55-
0
56-
);
57-
58-
my $t_npref = q{can't connect; 'on_connect_error' used};
59-
isa_ok( $t_cli_err, 'AnyEvent::RipeRedis::Error' );
60-
like( $t_cli_err->message, qr/^Can't connect to localhost:$port:/,
61-
"$t_npref; client error message" );
62-
isa_ok( $t_cmd_err, 'AnyEvent::RipeRedis::Error' );
63-
like( $t_cmd_err->message,
64-
qr/^Operation "ping" aborted: Can't connect to localhost:$port:/,
65-
"$t_npref; command error message" );
66-
is( $t_cmd_err->code, E_CANT_CONN, "$t_npref; command error code" );
67-
68-
return;
69-
}
70-
71-
sub t_cant_connect_mth2 {
22+
sub t_cant_connect {
7223
my $redis;
7324
my $port = empty_port();
7425

@@ -133,7 +84,7 @@ sub t_no_connection {
13384
connection_timeout => 3,
13485
reconnect => 0,
13586

136-
on_connect_error => sub {
87+
on_error => sub {
13788
$t_cli_err = shift;
13889
},
13990
);

0 commit comments

Comments
 (0)