49
49
TimeoutError ,
50
50
)
51
51
from redis .typing import EncodableT
52
- from redis .utils import HIREDIS_AVAILABLE , str_if_bytes
52
+ from redis .utils import HIREDIS_AVAILABLE , get_lib_version , str_if_bytes
53
53
54
54
from .._parsers import (
55
55
BaseParser ,
@@ -101,6 +101,8 @@ class AbstractConnection:
101
101
"db" ,
102
102
"username" ,
103
103
"client_name" ,
104
+ "lib_name" ,
105
+ "lib_version" ,
104
106
"credential_provider" ,
105
107
"password" ,
106
108
"socket_timeout" ,
@@ -140,6 +142,8 @@ def __init__(
140
142
socket_read_size : int = 65536 ,
141
143
health_check_interval : float = 0 ,
142
144
client_name : Optional [str ] = None ,
145
+ lib_name : Optional [str ] = "redis-py" ,
146
+ lib_version : Optional [str ] = get_lib_version (),
143
147
username : Optional [str ] = None ,
144
148
retry : Optional [Retry ] = None ,
145
149
redis_connect_func : Optional [ConnectCallbackT ] = None ,
@@ -157,6 +161,8 @@ def __init__(
157
161
self .pid = os .getpid ()
158
162
self .db = db
159
163
self .client_name = client_name
164
+ self .lib_name = lib_name
165
+ self .lib_version = lib_version
160
166
self .credential_provider = credential_provider
161
167
self .password = password
162
168
self .username = username
@@ -347,9 +353,23 @@ async def on_connect(self) -> None:
347
353
if str_if_bytes (await self .read_response ()) != "OK" :
348
354
raise ConnectionError ("Error setting client name" )
349
355
350
- # if a database is specified, switch to it
356
+ # set the library name and version, pipeline for lower startup latency
357
+ if self .lib_name :
358
+ await self .send_command ("CLIENT" , "SETINFO" , "LIB-NAME" , self .lib_name )
359
+ if self .lib_version :
360
+ await self .send_command ("CLIENT" , "SETINFO" , "LIB-VER" , self .lib_version )
361
+ # if a database is specified, switch to it. Also pipeline this
351
362
if self .db :
352
363
await self .send_command ("SELECT" , self .db )
364
+
365
+ # read responses from pipeline
366
+ for _ in (sent for sent in (self .lib_name , self .lib_version ) if sent ):
367
+ try :
368
+ await self .read_response ()
369
+ except ResponseError :
370
+ pass
371
+
372
+ if self .db :
353
373
if str_if_bytes (await self .read_response ()) != "OK" :
354
374
raise ConnectionError ("Invalid Database" )
355
375
0 commit comments