RedisCommandHandler

public final class RedisCommandHandler

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, logger: Logger = Logger(label: "RediStack.CommandHandler"))

    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.

    logger

    The Logging.Logger instance to use. The logger will have a Foundation.UUID value attached as metadata to uniquely identify this instance.

  • See NIO.ChannelInboundHandler.InboundIn

    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 error.

    A Logging.LogLevel.critical message will be written with the caught error.

    Declaration

    Swift

    public func errorCaught(context: ChannelHandlerContext, error: Error)
  • 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)
  • 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 the Channel. This unwraps a RedisCommand, storing the NIO.EventLoopPromise in a command queue, to fulfill later with the response to the command that is about to be sent through the NIO.Channel.

    See NIO.ChannelOutboundHandler.write(context:data:promise:)

    Declaration

    Swift

    public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?)