Programmer Reference : Redis : EsRedisCommandBatcher
EsRedisCommandBatcher
This is an abstract superclass that provides a common foundation for executing multiple Redis commands in a single batch. It is not intended to be instantiated directly. Its concrete subclasses, <EsRedisPipeline> and <EsRedisTransaction>, implement specific batching strategies.
You interact with subclasses of <EsRedisCommandBatcher> through the EsRedisClient>>pipeline: and EsRedisClient>>transaction: methods.
This class centralizes the shared logic for batch operations, including:
  • Managing the collection of commands and their reply converters.
  • Handling the asynchronous <EsFuture>/<EsPromise> mechanism for both individual commands and the entire batch.
  • Intercepting command group messages (like strings, hashes, etc.) and creating temporary, rewired command groups that queue commands to the batcher instead of sending them directly to the server.
Subclasses are responsible for implementing the specific command queuing and execution logic that defines their behavior (e.g., performance-focused pipelining vs. atomic transactions).
Instance Variables
  • client - <EsRedisClient> A reference to the client that created this command batcher.
  • commandCount - <Integer> The number of commands that have been queued for execution.
  • replyConverters - <OrderedCollection> A collection of the reply converter classes for each queued command.
  • masterPromise - <EsPromise> The promise associated with the entire batch operation. In async mode, it is completed with an array of all results when the batch finishes.
  • commandPromises - <OrderedCollection> A collection of EsPromise instances, where each promise corresponds to a single command queued in the batch. This allows each command in an async batch to return its own
    future.
Subclass Responbilities
command:as:: Subclasses must implement this method to define how a command is queued. For example, a pipeline appends the command to the client's output buffer, while a transaction queues it for later execution within a MULTI/EXEC block.
  • syncExecute: and asyncExecute:: Subclasses must implement these private methods to define the specific execution flow for synchronous and asynchronous modes, respectively. This includes sending the commands to Redis and handling their replies. These methods are invoked by the public execute: method.
Class Methods
newWithClient:
  Create a new, initialized instance for a client.
     This is the designated factory method for creating command batchers
     like pipelines and transactions is intended for internal use by EsRedisClient.
    
     Arguments:
        anEsRedisClient - <EsRedisClient> The client that will execute the command batch.
     Answers:
        <EsRedisCommandBatcher subclass> A new, initialized instance.
Instance Methods
execute:
  Execute the block. This is the main entry point for running command batchers.
     It handles both synchronous and asynchronous modes based on the client's state.
pipeline:
  Delegation - Execute a block of commands in a pipeline. The block receives an
     EsRedisPipeline instance on which to send commands. This method now
     delegates the entire execution flow to the pipeline object itself.
     For nested pipelines, this is a no-op that simply executes the block against
     the current pipeline instance.
    
     Arguments:
        aBlock - <Block> A one-argument block that receives the <EsRedisPipeline> instance.
     Answers:
        <Array> The array of replies in synchronous mode.
        <EsFuture> In async mode, a future that completes with the array of replies.
transaction:
  Delegation - Execute a block of commands atomically using MULTI/EXEC. This method now
     delegates the entire execution flow to the transaction object itself.
    
     Arguments:
        aBlock - <Block> A one-argument block that receives the <EsRedisTransaction> instance.
     Answers:
        <Array> The array of replies in synchronous mode.
        <EsFuture> In async mode, a future that completes with the array of replies.
Last modified date: 01/22/2026