Skip to content

Commit 6825451

Browse files
committed
Improve RedisConnection.close() to send a QUIT command to Redis before closing the channel from the client
1 parent 35a4fa0 commit 6825451

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/NIORedis/RedisConnection.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ public final class RedisConnection {
2828
/// - Returns: An `EventLoopFuture` that resolves when the connection has been closed.
2929
@discardableResult
3030
public func close() -> EventLoopFuture<Void> {
31-
guard _isClosed.exchange(with: true) else { return channel.eventLoop.makeSucceededFuture(()) }
31+
guard !_isClosed.exchange(with: true) else { return channel.eventLoop.makeSucceededFuture(()) }
3232

33-
let promise = channel.eventLoop.makePromise(of: Void.self)
34-
35-
channel.close(promise: promise)
36-
37-
return promise.futureResult
33+
return send(command: "QUIT")
34+
.flatMap { _ in
35+
let promise = self.channel.eventLoop.makePromise(of: Void.self)
36+
self.channel.close(promise: promise)
37+
return promise.futureResult
38+
}
3839
}
3940

4041
/// Sends the desired command with the specified arguments.

0 commit comments

Comments
 (0)