@@ -80,6 +80,9 @@ extension RedisConnection {
8080 }
8181 /// The port of the connection address. If the address is a Unix socket, then it will be `nil`.
8282 public var port : Int ? { self . address. port }
83+ /// The user name used to authenticate connections with.
84+ /// - Warning: This property should only be provided if you are running against Redis 6 or higher.
85+ public let username : String ?
8386 /// The password used to authenticate the connection.
8487 public let password : String ?
8588 /// The initial database index that the connection should use.
@@ -91,15 +94,17 @@ extension RedisConnection {
9194
9295 /// Creates a new connection configuration with the provided details.
9396 /// - Parameters:
94- /// - address: The socket address information to use for creating the Redis connection.
95- /// - password: The optional password to authenticate the connection with. The default is `nil`.
96- /// - initialDatabase: The optional database index to initially connect to. The default is `nil`.
97- /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
98- /// - defaultLogger: The optional prototype logger to use as the default logger instance when generating logs from the connection.
97+ /// - `address`: The socket address information to use for creating the Redis connection.
98+ /// - `username`: The optional username to authenticate the connection with. The default is `nil`.
99+ /// - `password`: The optional password to authenticate the connection with. The default is `nil`.
100+ /// - `initialDatabase`: The optional database index to initially connect to. The default is `nil`.
101+ /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
102+ /// - `defaultLogger`: The optional prototype logger to use as the default logger instance when generating logs from the connection.
99103 /// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
100104 /// - Throws: `RedisConnection.Configuration.ValidationError` if invalid arguments are provided.
101105 public init (
102106 address: SocketAddress ,
107+ username: String ? = nil ,
103108 password: String ? = nil ,
104109 initialDatabase: Int ? = nil ,
105110 defaultLogger: Logger ? = nil
@@ -109,11 +114,36 @@ extension RedisConnection {
109114 }
110115
111116 self . address = address
117+ self . username = username
112118 self . password = password
113119 self . initialDatabase = initialDatabase
114120 self . defaultLogger = defaultLogger ?? Configuration . defaultLogger
115121 }
116122
123+ /// Creates a new connection configuration with the provided details.
124+ /// - Parameters:
125+ /// - `address`: The socket address information to use for creating the Redis connection.
126+ /// - `password`: The optional password to authenticate the connection with. The default is `nil`.
127+ /// - `initialDatabase`: The optional database index to initially connect to. The default is `nil`.
128+ /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
129+ /// - `defaultLogger`: The optional prototype logger to use as the default logger instance when generating logs from the connection.
130+ /// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
131+ /// - Throws: `RedisConnection.Configuration.ValidationError` if invalid arguments are provided.
132+ public init (
133+ address: SocketAddress ,
134+ password: String ? = nil ,
135+ initialDatabase: Int ? = nil ,
136+ defaultLogger: Logger ? = nil
137+ ) throws {
138+ try self . init (
139+ address: address,
140+ username: nil ,
141+ password: password,
142+ initialDatabase: initialDatabase,
143+ defaultLogger: defaultLogger
144+ )
145+ }
146+
117147 /// Creates a new connection configuration with exact details.
118148 /// - Parameters:
119149 /// - hostname: The remote hostname to connect to.
@@ -214,6 +244,9 @@ extension RedisConnectionPool {
214244 // this needs to be var so it can be updated by the pool with the pool id
215245 /// The logger prototype that will be used by connections by default when generating logs.
216246 public internal( set) var connectionDefaultLogger : Logger
247+ /// The username used to authenticate connections.
248+ /// - Warning: This property should only be provided if you are running against Redis 6 or higher.
249+ public let connectionUsername : String ?
217250 /// The password used to authenticate connections.
218251 public let connectionPassword : String ?
219252 /// The initial database index that connections should use.
@@ -224,7 +257,7 @@ extension RedisConnectionPool {
224257 /// Creates a new connection factory configuration with the provided options.
225258 /// - Parameters:
226259 /// - connectionInitialDatabase: The optional database index to initially connect to. The default is `nil`.
227- /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
260+ /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
228261 /// - connectionPassword: The optional password to authenticate connections with. The default is `nil`.
229262 /// - connectionDefaultLogger: The optional prototype logger to use as the default logger instance when generating logs from connections.
230263 /// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
@@ -234,8 +267,34 @@ extension RedisConnectionPool {
234267 connectionPassword: String ? = nil ,
235268 connectionDefaultLogger: Logger ? = nil ,
236269 tcpClient: ClientBootstrap ? = nil
270+ ) {
271+ self . init (
272+ connectionInitialDatabase: connectionInitialDatabase,
273+ connectionUsername: nil ,
274+ connectionPassword: connectionPassword,
275+ connectionDefaultLogger: connectionDefaultLogger,
276+ tcpClient: tcpClient
277+ )
278+ }
279+
280+ /// Creates a new connection factory configuration with the provided options.
281+ /// - Parameters:
282+ /// - connectionInitialDatabase: The optional database index to initially connect to. The default is `nil`.
283+ /// Redis by default opens connections against index `0`, so only set this value if the desired default is not `0`.
284+ /// - connectionUsername: The optional username to authenticate connections with. The default is `nil`. Works only with Redis 6 and greater.
285+ /// - connectionPassword: The optional password to authenticate connections with. The default is `nil`.
286+ /// - connectionDefaultLogger: The optional prototype logger to use as the default logger instance when generating logs from connections.
287+ /// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
288+ /// - tcpClient: If you have chosen to configure a `NIO.ClientBootstrap` yourself, this will be used instead of the `.makeRedisTCPClient` factory instance.
289+ public init (
290+ connectionInitialDatabase: Int ? = nil ,
291+ connectionUsername: String ? = nil ,
292+ connectionPassword: String ? = nil ,
293+ connectionDefaultLogger: Logger ? = nil ,
294+ tcpClient: ClientBootstrap ? = nil
237295 ) {
238296 self . connectionInitialDatabase = connectionInitialDatabase
297+ self . connectionUsername = connectionUsername
239298 self . connectionPassword = connectionPassword
240299 self . connectionDefaultLogger = connectionDefaultLogger ?? RedisConnection . Configuration. defaultLogger
241300 self . tcpClient = tcpClient
0 commit comments