Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send SELECT if current database equals the one being selected #132

Merged
merged 1 commit into from Jul 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/Redis.pm
Expand Up @@ -172,9 +172,16 @@ sub is_subscriber { $_[0]{is_subscriber} }
sub select {
my $self = shift;
my $database = shift;
my $ret = $self->__std_cmd('select', $database, @_);
$self->{current_database} = $database;
$ret;

croak( "Cannot select an undefined redis database" )
unless defined $database;
# don't want to send multiple select() back and forth
if (!defined $self->{current_database} or $self->{current_database} ne $database) {
my $ret = $self->__std_cmd('select', $database, @_);
$self->{current_database} = $database;
return $ret;
};
return "OK"; # emulate redis response as of 3.0.6 just in case anybody cares
}

### we don't want DESTROY to fallback into AUTOLOAD
Expand Down Expand Up @@ -645,9 +652,11 @@ sub __on_connection {
$n = $n->($self) if ref($n) eq 'CODE';
$self->client_setname($n) if defined $n;
};


# don't use select() function as it's caching database name,
# rather call select directly
defined $self->{current_database}
and $self->select($self->{current_database});
and $self->__std_cmd('select', $self->{current_database});
}

foreach my $topic (CORE::keys(%{$self->{subscribers}})) {
Expand Down