Allow repeated commands to same connection in pool

Motivation:

Some Redis commands are very connection specific that have impacts on future access that makes it difficult in the current
checkout-use-return cycle that `RedisConnectionPool` uses.

Developers need a way to borrow a specific connection, chain several commands together, and then return the connection to the pool.

Modifications:

- Add: `leaseConnection` method to `RedisConnectionPool` which provides a connection from the pool and returns it after a provided closure's ELF resolves
- Add: `allowSubscriptions` property to `RedisConnection` for controlling the ability to make PubSub subscriptions
- Add: `RedisClientError.pubsubNotAllowed` case for when `RedisConnection.allowSubscriptions` is set to `false` and a subscription was still attempted

Result:

Developers should now have an "escape hatch" with `RedisConnectionPool` to do limited exclusive chains of operations on a specific connection.
This commit is contained in:
Nathan Harris
2020-10-15 13:39:58 -07:00
parent 56f0ab0bc0
commit 42e8d4b127
9 changed files with 188 additions and 8 deletions
@@ -75,14 +75,15 @@ open class RedisConnectionPoolIntegrationTestCase: XCTestCase {
}
public func makeNewPool(
connectionRetryTimeout: TimeAmount? = .seconds(5)
connectionRetryTimeout: TimeAmount? = .seconds(5),
minimumConnectionCount: Int = 0
) throws -> RedisConnectionPool {
let address = try SocketAddress.makeAddressResolvingHost(self.redisHostname, port: self.redisPort)
let pool = RedisConnectionPool(
serverConnectionAddresses: [address],
loop: self.eventLoopGroup.next(),
maximumConnectionCount: .maximumActiveConnections(4),
minimumConnectionCount: 0,
minimumConnectionCount: minimumConnectionCount,
connectionPassword: self.redisPassword,
connectionRetryTimeout: connectionRetryTimeout
)