RedisConnectionPool

public class RedisConnectionPool
extension RedisConnectionPool: RedisClient

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.

  • Create a new RedisConnectionPool.

    Declaration

    Swift

    public init(
        serverConnectionAddresses: [SocketAddress],
        loop: EventLoop,
        maximumConnectionCount: RedisConnectionPoolSize,
        minimumConnectionCount: Int = 1,
        connectionPassword: String? = nil,
        connectionLogger: Logger = .init(label: "RediStack.RedisConnection"),
        connectionTCPClient: ClientBootstrap? = nil,
        poolLogger: Logger = .init(label: "RediStack.RedisConnectionPool"),
        connectionBackoffFactor: Float32 = 2,
        initialConnectionBackoffDelay: TimeAmount = .milliseconds(100)
    )

    Parameters

    serverConnectionAddresses

    The set of Redis servers to which this pool is initially willing to connect. This set can be updated over time.

    loop

    The event loop to which this pooled client is tied.

    maximumConnectionCount

    The maximum number of connections to for this pool, either to be preserved or as a hard limit.

    minimumConnectionCount

    The minimum number of connections to preserve in the pool. If the pool is mostly idle and the Redis servers close these idle connections, the RedisConnectionPool will initiate new outbound connections proactively to avoid the number of available connections dropping below this number. Defaults to 1.

    connectionPassword

    The password to use to connect to the Redis servers in this pool.

    connectionLogger

    The Logger to pass to each connection in the pool.

    connectionTCPClient

    The base ClientBootstrap to use to create pool connections, if a custom one is in use.

    poolLogger

    The Logger used by the connection pool itself.

    connectionBackoffFactor

    Used when connection attempts fail to control the exponential backoff. This is a multiplicative factor, each connection attempt will be delayed by this amount times the previous delay.

    initialConnectionBackoffDelay

    If a TCP connection attempt fails, this is the first backoff value on the reconnection attempt. Subsequent backoffs are computed by compounding this value by connectionBackoffFactor.

  • Undocumented

    Declaration

    Swift

    public func activate()
  • Undocumented

    Declaration

    Swift

    public func close()
  • Updates the list of valid connection addresses.

    This does not invalidate existing connections: as long as those connections continue to stay up, they will be kept by this client. However, no new connections will be made to any endpoint that is not in newTargets.

    Declaration

    Swift

    public func updateConnectionAddresses(_ newAddresses: [SocketAddress])