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.
public init(initialQueueCapacity: Int = 3, logger: Logger = Logger(label: "RediStack.CommandHandler"))
The initial queue size to start with. The default is
RedisCommand.responsePromiseobjects 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.
Logging.Loggerinstance to use. The logger will have a
Foundation.UUIDvalue attached as metadata to uniquely identify this instance.
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.
ImportantThis will also close the socket connection to Redis.
RedisMetrics.commandFailureCountis not incremented from this error.
Logging.LogLevel.criticalmessage will be written with the caught error.
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
RESPValueresponse message to the promise waiting to be fulfilled at the front of the command queue.
RedisMetrics.commandSuccessCountare incremented from this method.
public func channelRead(context: ChannelHandlerContext, data: NIOAny)
Invoked by SwiftNIO when a
writehas been requested on the
Channel. This unwraps a
RedisCommand, storing the
NIO.EventLoopPromisein a command queue, to fulfill later with the response to the command that is about to be sent through the
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?)