@@ -202,6 +202,10 @@ class ClusterClient(
202202 :param read_timeout:
203203 Read Timeout.
204204 :type read_timeout: float
205+
206+ :param username:
207+ Username used for acl scl authentication. If not set, fall back use legacy auth.
208+ :type username: str
205209 """
206210 def __init__ (
207211 self ,
@@ -212,7 +216,9 @@ def __init__(
212216 slave_ok = False ,
213217 conn_timeout = 2 ,
214218 read_timeout = 2 ,
215- cluster_map = None ):
219+ cluster_map = None ,
220+ username = None
221+ ):
216222 super ().__init__ ()
217223 if not bool (seeds ) != bool (cluster_map ):
218224 raise PyRedisError ('Ether seeds or cluster_map has to be provided' )
@@ -229,6 +235,7 @@ def __init__(
229235 else :
230236 self ._map = ClusterMap (seeds = seeds )
231237 self ._map_id = self ._map .id
238+ self ._username = username
232239
233240 def _cleanup_conns (self ):
234241 hosts = self ._map .hosts (slave = self ._slave_ok )
@@ -250,7 +257,8 @@ def _connect(self, sock):
250257 read_only = self ._slave_ok ,
251258 encoding = self ._encoding ,
252259 password = self ._password ,
253- database = self ._database
260+ database = self ._database ,
261+ username = self ._username
254262 )
255263 self ._conns [sock ] = client
256264
@@ -364,7 +372,16 @@ class HashClient(
364372 - commands.String,
365373 - commands.Transaction
366374 """
367- def __init__ (self , buckets , database = 0 , password = None , encoding = None , conn_timeout = 2 , read_timeout = 2 ):
375+ def __init__ (
376+ self ,
377+ buckets ,
378+ database = None ,
379+ password = None ,
380+ encoding = None ,
381+ conn_timeout = 2 ,
382+ read_timeout = 2 ,
383+ username = None
384+ ):
368385
369386 super ().__init__ ()
370387 self ._conns = dict ()
@@ -378,7 +395,15 @@ def __init__(self, buckets, database=0, password=None, encoding=None, conn_timeo
378395 self ._closed = False
379396 self ._cluster = True
380397 self ._map = dict ()
381- self ._init_conns (buckets , database , password , encoding , conn_timeout , read_timeout )
398+ self ._init_conns (
399+ buckets = buckets ,
400+ database = database ,
401+ password = password ,
402+ encoding = encoding ,
403+ conn_timeout = conn_timeout ,
404+ read_timeout = read_timeout ,
405+ username = username
406+ )
382407 self ._init_map ()
383408
384409 def _bulk_fetch (self ):
@@ -401,14 +426,20 @@ def _execute_bulk(self, *args, conn):
401426 if self ._bulk_size_current == self ._bulk_size :
402427 self ._bulk_fetch ()
403428
404- def _init_conns (self , buckets , database , password , encoding , conn_timeout , read_timeout ):
429+ def _init_conns (self , buckets , database , password , encoding , conn_timeout , read_timeout , username ):
405430 for bucket in buckets :
406431 host , port = bucket
407432 bucketname = '{0}_{1}' .format (host , port )
408433 self ._conn_names .append (bucketname )
409434 self ._conns [bucketname ] = Connection (
410- host = host , port = port , database = database , password = password ,
411- encoding = encoding , conn_timeout = conn_timeout , read_timeout = read_timeout
435+ host = host ,
436+ port = port ,
437+ database = database ,
438+ password = password ,
439+ encoding = encoding ,
440+ conn_timeout = conn_timeout ,
441+ read_timeout = read_timeout ,
442+ username = username
412443 )
413444
414445 def _init_map (self ):
@@ -576,15 +607,27 @@ class SentinelClient(object):
576607 Password used for authentication of Sentinel instance itself. If None, no authentication is done.
577608 Only available starting with Redis 5.0.1.
578609 :type password: str
610+
611+ :param username:
612+ Username used for acl scl authentication. If not set, fall back use legacy auth.
613+ :type username: str
579614 """
580- def __init__ (self , sentinels , password = None ):
615+ def __init__ (self , sentinels , password = None , username = None ):
581616 self ._conn = None
582617 self ._sentinels = deque (sentinels )
583618 self ._password = password
619+ self ._username = username
584620
585621 def _sentinel_connect (self , sentinel ):
586622 host , port = sentinel
587- self ._conn = Connection (host = host , port = port , conn_timeout = 0.1 , sentinel = True , password = self ._password )
623+ self ._conn = Connection (
624+ host = host ,
625+ port = port ,
626+ conn_timeout = 0.1 ,
627+ sentinel = True ,
628+ password = self ._password ,
629+ username = self ._username
630+ )
588631 try :
589632 self .execute ('PING' )
590633 return True
0 commit comments