Module lettuce.core

Class CommandBatching

java.lang.Object
io.lettuce.core.dynamic.batch.CommandBatching

public abstract class CommandBatching
extends Object
Programmatic command batching API.

CommandBatching is used to queue commands in a batch queue and flush the command queue on command invocation. Usage:

 public interface MyCommands extends Commands {

   public void set(String key, String value, CommandBatching batching);

   public RedisFuture<String> get(String key, CommandBatching batching)
 }

 MyCommands commands = …

 commands.set("key", "value", CommandBatching.queue());
 commands.get("key", CommandBatching.flush());
 

Using CommandBatching in a method signature turns the command method into a batched command method.
Command batching executes commands in a deferred nature. This also means that at the time of invocation no result is available. Batching can be only used with synchronous methods without a return value (void) or asynchronous methods returning a RedisFuture. Reactive command batching is not supported because reactive executed commands maintain an own subscription lifecycle that is decoupled from command method batching.

Since:
5.0
Author:
Mark Paluch
See Also:
BatchSize
  • Constructor Details

    • CommandBatching

      public CommandBatching()
  • Method Details

    • flush

      public static CommandBatching flush()
      Flush the command batch queue after adding a command to the batch queue.
      Returns:
      CommandBatching to flush the command batch queue after adding a command to the batch queue.
    • queue

      public static CommandBatching queue()
      Enqueue the command to the batch queue.
      Returns:
      CommandBatching to enqueue the command to the batch queue.