Skip to content

Commit e168b6c

Browse files
committed
update to latest NIO2
1 parent 148ebdc commit e168b6c

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

Sources/NIORedis/ChannelHandlers/RedisCommandHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension RedisCommandHandler: ChannelInboundHandler {
3838
guard let leadPromise = commandResponseQueue.last else {
3939
return assertionFailure("Received unexpected error while idle: \(error.localizedDescription)")
4040
}
41-
leadPromise.fail(error: error)
41+
leadPromise.fail(error)
4242
}
4343

4444
/// Invoked by NIO when a read has been fired from earlier in the response chain. This forwards the unwrapped
@@ -56,8 +56,8 @@ extension RedisCommandHandler: ChannelInboundHandler {
5656
assert(popped != nil)
5757

5858
switch value {
59-
case .error(let e): leadPromise.fail(error: e)
60-
default: leadPromise.succeed(result: value)
59+
case .error(let e): leadPromise.fail(e)
60+
default: leadPromise.succeed(value)
6161
}
6262
}
6363
}

Sources/NIORedis/Commands/BasicCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension RedisConnection {
2626
public func delete(_ keys: String...) -> EventLoopFuture<Int> {
2727
let keyArgs = keys.map { RESPValue(bulk: $0) }
2828
return command("DEL", arguments: keyArgs)
29-
.thenThrowing { res in
29+
.flatMapThrowing { res in
3030
guard let count = res.int else {
3131
throw RedisError(identifier: "delete", reason: "Unexpected response: \(res)")
3232
}
@@ -43,7 +43,7 @@ extension RedisConnection {
4343
/// - Returns: A future bool indicating if the expiration was set or not.
4444
public func expire(_ key: String, after deadline: Int) -> EventLoopFuture<Bool> {
4545
return command("EXPIRE", arguments: [RESPValue(bulk: key), RESPValue(bulk: deadline.description)])
46-
.thenThrowing { res in
46+
.flatMapThrowing { res in
4747
guard let value = res.int else {
4848
throw RedisError(identifier: "expire", reason: "Unexpected response: \(res)")
4949
}

Sources/NIORedis/Extensions/NIO/ClientBootstrap.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ extension ClientBootstrap {
1717
ByteToMessageHandler(RESPDecoder()),
1818
RedisCommandHandler()
1919
]
20-
return EventLoopFuture<Void>.andAll(
21-
handlers.map { channel.pipeline.add(handler: $0) },
22-
eventLoop: group.next()
23-
)
20+
return .andAllSucceed(handlers.map { channel.pipeline.add(handler: $0) }, on: group.next())
2421
}
2522
}
2623
}

Sources/NIORedis/RedisConnection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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(result: ()) }
31+
guard _isClosed.exchange(with: true) else { return channel.eventLoop.makeSucceededFuture(()) }
3232

3333
let promise = channel.eventLoop.makePromise(of: Void.self)
3434

@@ -55,7 +55,7 @@ public final class RedisConnection {
5555
/// - Returns: An `EventLoopFuture` that will resolve with the Redis command response.
5656
public func command(_ command: String, arguments: [RESPValue] = []) -> EventLoopFuture<RESPValue> {
5757
guard !_isClosed.load() else {
58-
return channel.eventLoop.makeFailedFuture(error: RedisError.connectionClosed)
58+
return channel.eventLoop.makeFailedFuture(RedisError.connectionClosed)
5959
}
6060

6161
let promise = channel.eventLoop.makePromise(of: RESPValue.self)

Sources/NIORedis/RedisDriver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public final class RedisDriver {
5656

5757
return bootstrap.connect(host: hostname, port: port)
5858
.map { return RedisConnection(channel: $0) }
59-
.then { connection in
59+
.flatMap { connection in
6060
guard let pw = password else {
61-
return self.eventLoopGroup.next().makeSucceededFuture(result: connection)
61+
return self.eventLoopGroup.next().makeSucceededFuture(connection)
6262
}
6363

6464
return connection.authorize(with: pw).map { _ in return connection }
@@ -68,6 +68,6 @@ public final class RedisDriver {
6868

6969
private extension ChannelPipeline {
7070
func addHandlers(_ handlers: ChannelHandler...) -> EventLoopFuture<Void> {
71-
return EventLoopFuture<Void>.andAll(handlers.map { add(handler: $0) }, eventLoop: eventLoop)
71+
return .andAllSucceed(handlers.map { add(handler: $0) }, on: eventLoop)
7272
}
7373
}

Tests/NIORedisTests/RedisDriverTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class RedisDriverTests: XCTestCase {
1818

1919
override func tearDown() {
2020
_ = connection.command("FLUSHALL")
21-
.then { _ in self.connection.close() }
21+
.flatMap { _ in self.connection.close() }
2222
.map { _ in try? self.driver.terminate() }
2323
}
2424

0 commit comments

Comments
 (0)