Classes

The following classes are available globally.

  • Handles incoming byte messages from Redis and decodes them according to the Redis Serialization Protocol (RESP).

    See NIO.ByteToMessageDecoder, RESPTranslator and https://redis.io/topics/protocol

    See more

    Declaration

    Swift

    public final class RedisByteDecoder : ByteToMessageDecoder
  • 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.

    See more

    Declaration

    Swift

    public final class RedisCommandHandler
    extension RedisCommandHandler: ChannelInboundHandler
    extension RedisCommandHandler: ChannelOutboundHandler
  • Encodes outgoing RESPValue data into a raw ByteBuffer according to the Redis Serialization Protocol (RESP).

    See NIO.MessageToByteEncoder, RESPTranslator, and https://redis.io/topics/protocol

    See more

    Declaration

    Swift

    public final class RedisMessageEncoder : MessageToByteEncoder
  • A channel handler that stores a map of closures and channel or pattern names subscribed to in Redis using Pub/Sub.

    These RedisPubSubMessageReceiver closures are added and removed using methods directly on an instance of this handler.

    When a receiver is added or removed, the handler will send the appropriate subscribe or unsubscribe message to Redis so that the connection reflects the local Channel state.

    ChannelInboundHandler

    This handler is designed to be placed before a RedisCommandHandler so that it can intercept Pub/Sub messages and dispatch them to the appropriate receiver.

    If a response is not in the Pub/Sub message format as specified by Redis, then it is treated as a normal Redis command response and sent further into the pipeline so that eventually a RedisCommandHandler can process it.

    ChannelOutboundHandler

    This handler is what is defined as a “transparent” NIO.ChannelOutboundHandler in that it does absolutely nothing except forward outgoing commands in the pipeline.

    The reason why this handler needs to conform to this protocol at all, is that subscribe and unsubscribe commands are executed outside of a normal NIO.Channel.write(_:) cycle, as message receivers aren’t command arguments and need to be stored.

    All of this is outside the responsibility of the RedisCommandHandler, so the RedisPubSubHandler uses its own NIO.ChannelHandlerContext being before the command handler to short circuit the pipeline.

    RemovableChannelHandler

    As a connection can move in and out of “PubSub mode”, this handler is can be added and removed from a NIO.ChannelPipeline as needed.

    When the handler has received a removeHandler(context:removalToken:) request, it will remove itself immediately.

    See more

    Declaration

    Swift

    public final class RedisPubSubHandler
    extension RedisPubSubHandler: RemovableChannelHandler
    extension RedisPubSubHandler: ChannelInboundHandler
    extension RedisPubSubHandler: ChannelOutboundHandler
  • A concrete RedisClient implementation that represents an individual connection to a Redis database instance.

    For basic setups, you will just need a NIO.SocketAddress and a NIO.EventLoop and perhaps a password.

    let eventLoop: EventLoop = ...
    let connection = RedisConnection.connect(
        to: try .makeAddressResolvingHost("my.redis.url", port: RedisConnection.defaultPort),
        on: eventLoop
    ).wait()
    
    let result = try connection.set("my_key", to: "some value")
        .flatMap { return connection.get("my_key") }
        .wait()
    
    print(result) // Optional("some value")
    

    Note: wait() is used in the example for simplicity. Never call wait() on an event loop.

    See NIO.SocketAddress, NIO.EventLoop, and RedisClient.

    See more

    Declaration

    Swift

    public final class RedisConnection : RedisClient, RedisClientWithUserContext
  • A RedisConnectionPool is an implementation of RedisClient backed by a pool of connections to Redis, rather than a single one.

    RedisConnectionPool uses a pool of connections on a single EventLoop to manage its activity. This pool may vary in size and strategy, including how many active connections it tries to manage at any one time and how it responds to demand for connections beyond its upper limit.

    Note that RedisConnectionPool is entirely thread-safe, even though all of its connections belong to a single EventLoop: if callers call the API from a different EventLoop (or from no EventLoop at all) RedisConnectionPool will ensure that the call is dispatched to the correct loop.

    See more

    Declaration

    Swift

    public class RedisConnectionPool
    extension RedisConnectionPool: RedisClient