From 25ac4eb75ef66fb3f8e1a5f5c500263a3e1d5bf7 Mon Sep 17 00:00:00 2001 From: Nick Spreen Date: Thu, 3 Aug 2023 16:55:36 -0400 Subject: [PATCH] Add username param for auth command. --- Sources/SwiftRedis/Redis.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftRedis/Redis.swift b/Sources/SwiftRedis/Redis.swift index 0354411..ef9ba1d 100644 --- a/Sources/SwiftRedis/Redis.swift +++ b/Sources/SwiftRedis/Redis.swift @@ -52,10 +52,17 @@ public class Redis { /// Authenticate against the server /// /// - Parameter pswd: String for the password. + /// - Parameter username: String for the username (optional). /// - Parameter callback: callback function that is called after authenticating, /// NSError will be nil if successful. - public func auth(_ pswd: String, callback: (NSError?) -> Void) { - + public func auth(_ pswd: String, with username: String? = nil, callback: (NSError?) -> Void) { + if let username = username { + issueCommand("AUTH", username, pswd) {(response: RedisResponse) in + let (_, error) = self.redisOkResponseHandler(response, nilOk: false) + callback(error) + } + return + } issueCommand("AUTH", pswd) {(response: RedisResponse) in let (_, error) = self.redisOkResponseHandler(response, nilOk: false) callback(error)