redis/jedis · error · UnsupportedOperationException

Broadcast command is only supported in…

Error message

Broadcast command is only supported in ClusterCommandExecutor

What it means

RedisClusterClient.broadcastCommand() sends a command to every primary node in the cluster and aggregates replies, which only ClusterCommandExecutor knows how to do. When the configured executor is not a ClusterCommandExecutor the method throws UnsupportedOperationException with this message, as documented by its @throws tag.

Solutions

  1. Use the default ClusterCommandExecutor by building the client through the standard RedisClusterClient builder.
  2. Guard with `client.getExecutor() instanceof ClusterCommandExecutor` (or instanceof on the client type) before calling broadcastCommand.
  3. In non-cluster deployments, loop over the single connection/provider yourself instead of broadcasting.

Example fix

// before
client.broadcastCommand(commandObjects.configSet("maxmemory", "1gb"));

// after
if (executor instanceof ClusterCommandExecutor) {
  client.broadcastCommand(commandObjects.configSet("maxmemory", "1gb"));
} else {
  client.configSet("maxmemory", "1gb");
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(client instanceof RedisClusterClient)) {
  throw new IllegalStateException("broadcastCommand requires a cluster client");
}

Try / catch

try {
  client.broadcastCommand(cmd);
} catch (UnsupportedOperationException e) {
  // non-cluster executor: apply per-node instead
  applySingleNode(cmd);
}

Prevention

When it happens

Trigger: Invoking broadcastCommand(commandObject) (e.g. CONFIG SET, FLUSHALL-style broadcast) on a RedisClusterClient built with a non-cluster executor, such as a custom executor injected through a builder subclass or test harness.

Common situations: Replacing the executor to add retries/metrics without realizing broadcast is cluster-specific; running the same code against a standalone-backed client; unit tests that mock executors with a simple implementation.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/58dd040e8d19de8d. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/RedisClusterClient.java:285

          "Support only execute to replica in ClusterCommandExecutor");
    }
    return ((ClusterCommandExecutor) executor).executeCommandToReplica(commandObject);
  }

  /**
   * Broadcast a command to all primary nodes in the cluster.
   * <p>
   * This method is useful for administrative commands that need to be executed on all primary nodes,
   * such as {@code PING}, {@code CONFIG SET}, {@code FLUSHALL}, etc.
   * </p>
   * @param commandObject the command to broadcast
   * @param <T> the return type of the command
   * @return the aggregated reply from all primary nodes
   * @throws UnsupportedOperationException if the executor is not a ClusterCommandExecutor
   */
  public final <T> T broadcastCommand(CommandObject<T> commandObject) {
    if (!(executor instanceof ClusterCommandExecutor)) {
      throw new UnsupportedOperationException(
          "Broadcast command is only supported in ClusterCommandExecutor");
    }
    return ((ClusterCommandExecutor) executor).broadcastCommand(commandObject, true);
  }

  // ==================== Multi-Shard Command Methods ====================
  // These methods execute commands across multiple Redis cluster shards when keys
  // hash to different slots, aggregating the results appropriately.

  private <T> T executeMultiShardCommand(List<CommandObject<T>> commandObjects) {
    if (!(executor instanceof ClusterCommandExecutor)) {
      throw new UnsupportedOperationException(
          "Multi-shard command is only supported in ClusterCommandExecutor");
    }
    return ((ClusterCommandExecutor) executor).executeMultiShardCommand(commandObjects);
  }

  /**

View on GitHub (pinned to 6dac31d4c2)