@@ -80,6 +80,9 @@ extension RedisConnection {
80
80
}
81
81
/// The port of the connection address. If the address is a Unix socket, then it will be `nil`.
82
82
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 ?
83
86
/// The password used to authenticate the connection.
84
87
public let password : String ?
85
88
/// The initial database index that the connection should use.
@@ -91,15 +94,17 @@ extension RedisConnection {
91
94
92
95
/// Creates a new connection configuration with the provided details.
93
96
/// - 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.
99
103
/// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
100
104
/// - Throws: `RedisConnection.Configuration.ValidationError` if invalid arguments are provided.
101
105
public init (
102
106
address: SocketAddress ,
107
+ username: String ? = nil ,
103
108
password: String ? = nil ,
104
109
initialDatabase: Int ? = nil ,
105
110
defaultLogger: Logger ? = nil
@@ -109,11 +114,36 @@ extension RedisConnection {
109
114
}
110
115
111
116
self . address = address
117
+ self . username = username
112
118
self . password = password
113
119
self . initialDatabase = initialDatabase
114
120
self . defaultLogger = defaultLogger ?? Configuration . defaultLogger
115
121
}
116
122
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
+
117
147
/// Creates a new connection configuration with exact details.
118
148
/// - Parameters:
119
149
/// - hostname: The remote hostname to connect to.
@@ -214,6 +244,9 @@ extension RedisConnectionPool {
214
244
// this needs to be var so it can be updated by the pool with the pool id
215
245
/// The logger prototype that will be used by connections by default when generating logs.
216
246
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 ?
217
250
/// The password used to authenticate connections.
218
251
public let connectionPassword : String ?
219
252
/// The initial database index that connections should use.
@@ -224,7 +257,7 @@ extension RedisConnectionPool {
224
257
/// Creates a new connection factory configuration with the provided options.
225
258
/// - Parameters:
226
259
/// - 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`.
228
261
/// - connectionPassword: The optional password to authenticate connections with. The default is `nil`.
229
262
/// - connectionDefaultLogger: The optional prototype logger to use as the default logger instance when generating logs from connections.
230
263
/// If one is not provided, one will be generated. See `RedisLogging.baseConnectionLogger`.
@@ -234,8 +267,34 @@ extension RedisConnectionPool {
234
267
connectionPassword: String ? = nil ,
235
268
connectionDefaultLogger: Logger ? = nil ,
236
269
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
237
295
) {
238
296
self . connectionInitialDatabase = connectionInitialDatabase
297
+ self . connectionUsername = connectionUsername
239
298
self . connectionPassword = connectionPassword
240
299
self . connectionDefaultLogger = connectionDefaultLogger ?? RedisConnection . Configuration. defaultLogger
241
300
self . tcpClient = tcpClient
0 commit comments