Permalink
Browse files

Factor out new __with_reconnect method

  • Loading branch information...
1 parent 4dabb72 commit fb5f5bd66f5579e85e74196b886e908ed9a3ee01 @arc committed Mar 5, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/Redis.pm
View
@@ -223,18 +223,26 @@ sub __std_cmd {
$self->__is_valid_command($command);
+ my @cmd_args = @_;
+ return $self->__with_reconnect(sub {
+ $self->__run_cmd($command, @cmd_args);
+ });
+}
+
+sub __with_reconnect {
+ my ($self, $cb) = @_;
+
## Fast path, no reconnect
- return $self->__run_cmd($command, @_) unless $self->{reconnect};
+ return $cb->() unless $self->{reconnect};
- my @cmd_args = @_;
return try {
- $self->__run_cmd($command, @cmd_args);
+ $cb->();
}
catch {
die $_ unless ref($_) eq 'Redis::X::Reconnect';
$self->__connect;
- $self->__run_cmd($command, @cmd_args);
+ $cb->();
};
}

0 comments on commit fb5f5bd

Please sign in to comment.