Skip to content

Commit d0da3e7

Browse files
committed
Improve Redis Channel Pipeline Debugging
Motivation: Debugging and properly handling errors was difficult as the `ChannelHandler` names were the default generic names, in addition the `RedisCommandHandler` did not pipe errors further up the pipeline. Modifications: `RedisCommandHandler` now calls `context.fireErrorCaught(error)` when receiving errors, and the default Redis `ChannelPipeline` handlers are added with debugging names. Result: It should be easier for debugging purposes to work with any Redis `ChannelPipeline`.
1 parent 1a9f086 commit d0da3e7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Sources/NIORedis/ChannelHandlers/RedisCommandHandler.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extension RedisCommandHandler: ChannelInboundHandler {
6262
return assertionFailure("Received unexpected error while idle: \(error.localizedDescription)")
6363
}
6464
leadPromise.fail(error)
65+
context.fireErrorCaught(error)
6566
}
6667

6768
/// Invoked by NIO when a read has been fired from earlier in the response chain. This forwards the unwrapped

Sources/NIORedis/Redis.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ extension Redis {
3636
ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR),
3737
value: 1
3838
)
39-
.channelInitializer { $0.pipeline.addHandlers([
40-
MessageToByteHandler(RedisMessageEncoder()),
41-
ByteToMessageHandler(RedisByteDecoder()),
42-
RedisCommandHandler()
43-
])}
39+
.channelInitializer { channel in
40+
let handlers: [(ChannelHandler, String)] = [
41+
(MessageToByteHandler(RedisMessageEncoder()), "NIORedis.Outgoing"),
42+
(ByteToMessageHandler(RedisByteDecoder()), "NIORedis.Incoming"),
43+
(RedisCommandHandler(), "NIORedis.Queue")
44+
]
45+
return .andAllSucceed(
46+
handlers.map { channel.pipeline.addHandler($0, name: $1) },
47+
on: group.next()
48+
)
49+
}
4450
}
4551
}
4652

0 commit comments

Comments
 (0)