Programmer Reference : Redis : EsRedisClientPool
EsRedisClientPool
Description
Provides a high-level, thread-safe manager for a pool of <EsRedisClient> connections. Its primary purpose is to improve performance and manage resources in concurrent applications where multiple processes require access to Redis simultaneously. By maintaining a collection of ready-to-use client connections, it eliminates the overhead of repeatedly establishing new connections for each request.
This class is not a polymorphic, drop-in replacement for <EsRedisClient>. It is a specialized resource manager. Its sole public API for Redis operations is the #executeWithClient: method. This design enforces a clear and safe pattern for all interactions with the pool, where a dedicated client is temporarily "leased" to a block of code, ensuring that stateful operations (like transactions) are handled correctly on a single connection.
Instance Variables
  • allClients - <OrderedCollection> Holds all <EsRedisClient> instances created and
managed by the pool for their entire lifecycle.
  • pool - <OrderedCollection> A queue of currently available, idle client connections read to be leased.
  • poolLock - <Semaphore> A mutex (Semaphore forMutualExclusion) to ensure thread-safe
access to the internal pool collection.
  • poolSemaphore - <Semaphore> Controls access to the pool, tracking the number of
available clients. Processes wait on this semaphore when the pool is empty.
  • isAsync - <Boolean> A flag indicating if the clients managed by the pool operate in
synchronous or asynchronous mode.
  • state - <Symbol> The current state of the pool (#connected or #disconnected).
Examples
Typical Usage (Synchronous)
| pool result |
pool := EsRedisClientPool host: '127.0.0.1' port: 6379 size: 10.
pool connect.
result := pool executeWithClient: [:client |
client strings set: 'mykey' value: 'myvalue'.
client strings get: 'mykey'
].
self assert: (result = 'myvalue').
pool disconnect.
Typical Usage (Asynchronous)
| pool future |
pool := EsRedisClientPool host: '127.0.0.1' port: 6379 size: 10.
pool isAsync: true.
future := pool connect then: [:p |
pool executeWithClient: [:client |
client strings set: 'mykey' value: 'async value'
]
].
future := future then: [:r | pool disconnect ].
future waitFor.
Stateful Transaction Example
| pool results |
pool := EsRedisClientPool host: '127.0.0.1' port: 6379 size: 10.
pool connect.
"The executeWithClient: block guarantees that WATCH, MULTI, and EXEC
all run on the same, dedicated connection."
results := pool executeWithClient: [:client |
client server watch: 'mykey'.
client transaction: [:tx |
tx strings incr: 'mykey'
]
].
pool disconnect.
Concurrent Workload Example
| pool jobs jobsLock completion |
pool := EsRedisClientPool host: '127.0.0.1' port: 6379 size: 5.
pool connect.

jobs := (1 to: 100) asOrderedCollection.
jobsLock := Semaphore forMutualExclusion.
completion := Semaphore new.

"Fork 5 worker processes that all pull from the same job queue."
5 timesRepeat: [
[
| job |
[
job := jobsLock critical: [
jobs isEmpty ifFalse: [jobs removeFirst]
].
job notNil
] whileTrue: [
pool executeWithClient: [:c |
c strings incr: 'job-counter'.
(Delay forMilliseconds: 2) wait
]
].
completion signal
] fork.
].

"Wait for all workers to finish."
5 timesRepeat: [completion wait].
pool disconnect.
Class Methods
host:port:size:
  Answer a new, configured instance of an EsRedisClientPool.
     The pool is created in a disconnected state. Call #connect to make it operational.
     
     Arguments:
        aString - <String> The hostname or IP address of the Redis server.
        anInteger - <Integer> The port number of the Redis server.
        anIntegerSize - <Integer> The number of clients to create in the pool.
     Answers:
        <EsRedisClientPool> A new, un-connected pool instance.
Instance Methods
connect
  Connect all underlying clients to the Redis server and make the pool operational.
     If the pool is already connected, this method has no effect.
     
     Answers:
        <EsRedisClientPool> In synchronous mode, answers the receiver.
        <EsFuture> In asynchronous mode, answers a future that completes with the receiver.
disconnect
  Disconnect all underlying clients from the Redis server, making the pool unusable.
     
     Answers:
        <EsRedisClientPool> In synchronous mode, answers the receiver.
        <EsFuture> In asynchronous mode, answers a future that completes with the receiver.
executeWithClient:
  Acquires a single client from the pool, executes aBlock with the client as an argument,
     and ensures the client is returned to the pool when the block completes.
     This is the correct way to perform a series of stateful operations (WATCH/MULTI/EXEC, SELECT, etc.).
     
     Arguments:
        aBlock - <Block> A one-argument block that receives a dedicated EsRedisClient instance.
     Answers:
        <Object> The result of the block execution.
        <EsFuture> If the block returns a future, this method returns that future.
     Raises:
        <EsRedisConnectionException> If the pool is disconnected.
isAsync
  Answer whether the pool is operating in asynchronous mode.
     
     Answers:
        <Boolean> True if in async mode, false otherwise.
isAsync:
  Set the pool's operating mode to asynchronous or synchronous.
     This setting is propagated to all underlying client connections.
     
     Arguments:
        aBoolean - <Boolean> True for asynchronous mode, false for synchronous mode.
isConnected
  Answer whether the pool is connected and ready to accept commands.
     
     Answers:
        <Boolean> True if the pool's state is connected, false otherwise.
Last modified date: 01/22/2026