From 5c52089e296a11389add537eb92ae0834fd2e4a0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 11 May 2023 17:53:51 -0400 Subject: [PATCH] make redis client connections hash non-global Signed-off-by: Bill Erickson --- src/perl/lib/OpenSRF/Transport/Redis/Client.pm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/perl/lib/OpenSRF/Transport/Redis/Client.pm b/src/perl/lib/OpenSRF/Transport/Redis/Client.pm index 53ac681..7220083 100644 --- a/src/perl/lib/OpenSRF/Transport/Redis/Client.pm +++ b/src/perl/lib/OpenSRF/Transport/Redis/Client.pm @@ -9,9 +9,6 @@ use OpenSRF::Transport; use OpenSRF::Transport::Redis::Message; use OpenSRF::Transport::Redis::BusConnection; -# Map of bus domain names to bus connections. -my %connections; - # There will only be one Client per process, but each client may # have multiple connections. my $_singleton; @@ -22,7 +19,10 @@ sub new { return $_singleton if $_singleton && !$force; - my $self = {service => $service}; + my $self = { + service => $service, + connections => {}, + }; bless($self, $class); @@ -70,7 +70,7 @@ sub add_connection { ); $connection->set_address(); - $connections{$domain} = $connection; + $self->{connections}->{$domain} = $connection; $connection->connect; @@ -80,7 +80,7 @@ sub add_connection { sub get_connection { my ($self, $domain) = @_; - my $con = $connections{$domain}; + my $con = $self->{connections}->{$domain}; return $con if $con; @@ -115,18 +115,18 @@ sub primary_domain { sub primary_connection { my $self = shift; - return $connections{$self->primary_domain}; + return $self->{connections}->{$self->primary_domain}; } sub disconnect { my ($self, $domain) = @_; - for my $domain (keys %connections) { - my $con = $connections{$domain}; + for my $domain (keys %{$self->{connections}}) { + my $con = $self->{connections}->{$domain}; $con->disconnect($self->primary_domain eq $domain); - delete $connections{$domain}; } + $self->{connections} = {}; $_singleton = undef; } -- 2.11.0