Skip to content

Commit 12aaa12

Browse files
committed
refactor: MULTI and subsequent commands
1 parent d57d00a commit 12aaa12

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

redis/connection.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,6 @@ def on_connect(self):
379379
raise ConnectionError("Invalid RESP version")
380380
# fall back to AUTH command (for Redis versions less than 6.0)
381381
else:
382-
self.send_command('MULTI')
383-
self.read_response()
384-
385-
# avoid checking health here -- PING will fail if we try
386-
# to check the health prior to the AUTH
387-
if auth_args:
388-
self.send_command("AUTH", *auth_args, check_health=False)
389-
auth_command_response = True
390382
# avoid checking health here -- PING will fail if we try
391383
# to check the health prior to the AUTH
392384
if auth_args:
@@ -396,24 +388,28 @@ def on_connect(self):
396388
else:
397389
self.send_command("AUTH", *auth_args, check_health=False)
398390

391+
# start a transaction block with MULTI
392+
try:
393+
self.send_command('MULTI')
394+
self.read_response()
399395

400-
# if a client_name is given, set it
401-
if self.client_name:
402-
self.send_command("CLIENT", "SETNAME", self.client_name)
396+
# if a client_name is given, set it
397+
if self.client_name:
398+
self.send_command("CLIENT", "SETNAME", self.client_name)
403399

404-
# set the library name and version
405-
if self.lib_name:
406-
self.send_command("CLIENT", "SETINFO", "LIB-NAME", self.lib_name)
407-
if self.lib_version:
408-
self.send_command("CLIENT", "SETINFO", "LIB-VER", self.lib_version)
400+
# set the library name and version
401+
if self.lib_name:
402+
self.send_command("CLIENT", "SETINFO", "LIB-NAME", self.lib_name)
403+
if self.lib_version:
404+
self.send_command("CLIENT", "SETINFO", "LIB-VER", self.lib_version)
409405

410-
# if a database is specified, switch to it
411-
if self.db:
412-
self.send_command("SELECT", self.db)
406+
# if a database is specified, switch to it
407+
if self.db:
408+
self.send_command("SELECT", self.db)
413409

414-
# if client caching is enabled, start tracking
415-
if self.client_cache:
416-
self.send_command("CLIENT", "TRACKING", "ON")
410+
# if client caching is enabled, start tracking
411+
if self.client_cache:
412+
self.send_command("CLIENT", "TRACKING", "ON")
417413

418414
# execute the MULTI block
419415
try:

0 commit comments

Comments
 (0)