Skip to content

Commit 5d6c3d3

Browse files
committed
Merge branch 'authorize' into 'master'
Add authorize command See merge request Mordil/swift-redi-stack!94
2 parents 8d85cb2 + 435cdb2 commit 5d6c3d3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Sources/RediStack/Commands/BasicCommands.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ extension RedisClient {
7171
.convertFromRESPValue(to: String.self)
7272
.map { return $0 == "OK" }
7373
}
74+
75+
/// Requests the client to authenticate with Redis to allow other commands to be executed.
76+
///
77+
/// [https://redis.io/commands/auth](https://redis.io/commands/auth)
78+
/// - Parameter password: The password to authenticate with.
79+
/// - Returns: A `NIO.EventLoopFuture` that resolves if the password was accepted, otherwise it fails.
80+
@inlinable
81+
public func authorize(with password: String) -> EventLoopFuture<Void> {
82+
let args = [RESPValue(bulk: password)]
83+
return send(command: "AUTH", with: args)
84+
.map { _ in return () }
85+
}
7486

7587
/// Removes the specified keys. A key is ignored if it does not exist.
7688
///

Sources/RediStack/RedisConnection.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ extension RedisConnection {
7171
guard let pw = password else {
7272
return connection.eventLoop.makeSucceededFuture(connection)
7373
}
74-
75-
let args = [RESPValue(bulk: pw)]
76-
return connection.send(command: "AUTH", with: args)
77-
.map { _ in return connection }
74+
return connection.authorize(with: pw)
75+
.map { return connection }
7876
}
7977
}
8078
}

0 commit comments

Comments
 (0)