Fix handling of unsupported client_list() command

This commit is contained in:
Tomas Van den Hauwe 2024-11-07 14:54:37 -08:00
parent bb7f340537
commit 7f4f114c12
1 changed files with 8 additions and 8 deletions

View File

@ -227,20 +227,20 @@ class BaseWorker:
if prepare_for_work: if prepare_for_work:
self.hostname: Optional[str] = socket.gethostname() self.hostname: Optional[str] = socket.gethostname()
self.pid: Optional[int] = os.getpid() self.pid: Optional[int] = os.getpid()
self.ip_address = 'unknown'
try: try:
connection.client_setname(self.name) connection.client_setname(self.name)
except redis.exceptions.ResponseError: except redis.exceptions.ResponseError:
warnings.warn('CLIENT SETNAME command not supported, setting ip_address to unknown', Warning) warnings.warn('CLIENT SETNAME command not supported, setting ip_address to unknown', Warning)
self.ip_address = 'unknown'
else: else:
try:
client_adresses = [ client_adresses = [
client['addr'] for client in connection.client_list() if client.get('name') == self.name client['addr'] for client in connection.client_list() if client.get('name') == self.name
] ]
if len(client_adresses) > 0: if len(client_adresses) > 0:
self.ip_address = client_adresses[0] self.ip_address = client_adresses[0]
else: except redis.exceptions.ResponseError:
warnings.warn('CLIENT LIST command not supported, setting ip_address to unknown', Warning) warnings.warn('CLIENT LIST command not supported, setting ip_address to unknown', Warning)
self.ip_address = 'unknown'
else: else:
self.hostname = None self.hostname = None
self.pid = None self.pid = None