RedisCommandHandler
public final class RedisCommandHandler
extension RedisCommandHandler: ChannelInboundHandler
extension RedisCommandHandler: ChannelOutboundHandler
An object that operates in a First In, First Out (FIFO) request-response cycle.
RedisCommandHandler
is a NIO.ChannelDuplexHandler
that sends RedisCommand
instances to Redis,
and fulfills the command’s NIO.EventLoopPromise
as soon as a RESPValue
response has been received from Redis.
-
Declaration
Swift
public init(initialQueueCapacity: Int = 3)
Parameters
initialQueueCapacity
The initial queue size to start with. The default is
3
.RedisCommandHandler
stores allRedisCommand.responsePromise
objects into a buffer, and unless you intend to execute several concurrent commands against Redis, and don’t want the buffer to resize, you shouldn’t need to set this parameter.
-
Declaration
Swift
public typealias InboundIn = RESPValue
-
Invoked by SwiftNIO when an error has been thrown. The command queue will be drained with each promise in the queue being failed with the error thrown.
See
NIO.ChannelInboundHandler.errorCaught(context:error:)
Important
This will also close the socket connection to Redis.Note
Note:RedisMetrics.commandFailureCount
is not incremented from this method.Declaration
Swift
public func errorCaught(context: ChannelHandlerContext, error: Error)
-
Invoked by SwiftNIO when the channel’s active state has changed, such as when it is closed. The command queue will be drained with each promise in the queue being failed from a connection closed error.
See
NIO.ChannelInboundHandler.channelInactive(context:)
Note
RedisMetrics.commandFailureCount
is not incremented from this method.Declaration
Swift
public func channelInactive(context: ChannelHandlerContext)
-
Invoked by SwiftNIO when a read has been fired from earlier in the response chain.
This forwards the decoded
RESPValue
response message to the promise waiting to be fulfilled at the front of the command queue.Note
RedisMetrics.commandFailureCount
andRedisMetrics.commandSuccessCount
are incremented from this method.See
NIO.ChannelInboundHandler.channelRead(context:data:)
Declaration
Swift
public func channelRead(context: ChannelHandlerContext, data: NIOAny)
-
See
NIO.ChannelOutboundHandler.OutboundIn
Declaration
Swift
public typealias OutboundIn = RedisCommand
-
See
NIO.ChannelOutboundHandler.OutboundOut
Declaration
Swift
public typealias OutboundOut = RESPValue
-
Invoked by SwiftNIO when a
write
has been requested on theChannel
.This unwraps a
RedisCommand
, storing theNIO.EventLoopPromise
in a command queue, to fulfill later with the response to the command that is about to be sent through theNIO.Channel
.See
NIO.ChannelOutboundHandler.write(context:data:promise:)
Declaration
Swift
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?)