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.

  • The data payload that the command handler is expecting to receive in the channel to process sending to Redis.

    message

    This value is expected to be a fully serialized command with it’s keyword and arguments in a bulk string array ready to be sent to Redis as-is.

    responsePromise

    This is a NIO.EventLoopPromise that will be resolved once a response from Redis has been received.

    Declaration

    Swift

    public typealias OutboundCommandPayload = (message: RESPValue, responsePromise: EventLoopPromise<RESPValue>)
  • Declaration

    Swift

    public init(initialQueueCapacity: Int = 3)

    Parameters

    initialQueueCapacity

    The initial queue size to start with. The default is 3. RedisCommandHandler stores all RedisCommand.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 and RedisMetrics.commandSuccessCount are incremented from this method.

    See NIO.ChannelInboundHandler.channelRead(context:data:)

    Declaration

    Swift

    public func channelRead(context: ChannelHandlerContext, data: NIOAny)