Skip to content

Implement pooled RedisClient

Lukasa requested to merge lukasa/RediStack:cb-pooled-client-master into master

Motivation

In many applications it's important to provide a system for managing connections to a database like Redis. These applications want to be able to hand connections out to individual users without necessarily needing to manage them themselves, and to preserve connections across request contexts. This requires a connection pool, and then a mapping from the pool to the RedisClient protocol.

I appreciate that in the past this project has shied away from providing a connection pool. This is reasonable, but the SSWG has thus far not wanted to try to define a standard pool until we have an appropriate number of examples to generalise from. This provides a third example in the ecosystem which we can use to try to generalise. As the pool itself is a pure implementation detail for RediStack, we can always swap out for a general-purpose one in future and drop the code in RediStack.

The API for RedisPooledClient is currently very simple. This is intentional: we can always widen it later, but for now I wanted something that was minimal but usable.

Modifications

  • Implement RedisPooledClient.
  • Implemented new ConnectionPool object.
  • Added new RedisConnectionPoolError type.
  • Tests.

Result

Users will have access to a pool of Redis connections that they can use to make Redis queries.

Checklist

  • Copyright headers in new files (see CONTRIBUTING.md)
  • Unit tests added
  • API Documentation comments

Merge request reports