{"record":{"id":"58dd040e8d19de8d","repo":"redis/jedis","slug":"broadcast-command-is-only-supported-in-clustercomm","errorCode":null,"errorMessage":"Broadcast command is only supported in ClusterCommandExecutor","messagePattern":"Broadcast command is only supported in ClusterCommandExecutor","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/RedisClusterClient.java","lineNumber":285,"sourceCode":"          \"Support only execute to replica in ClusterCommandExecutor\");\n    }\n    return ((ClusterCommandExecutor) executor).executeCommandToReplica(commandObject);\n  }\n\n  /**\n   * Broadcast a command to all primary nodes in the cluster.\n   * <p>\n   * This method is useful for administrative commands that need to be executed on all primary nodes,\n   * such as {@code PING}, {@code CONFIG SET}, {@code FLUSHALL}, etc.\n   * </p>\n   * @param commandObject the command to broadcast\n   * @param <T> the return type of the command\n   * @return the aggregated reply from all primary nodes\n   * @throws UnsupportedOperationException if the executor is not a ClusterCommandExecutor\n   */\n  public final <T> T broadcastCommand(CommandObject<T> commandObject) {\n    if (!(executor instanceof ClusterCommandExecutor)) {\n      throw new UnsupportedOperationException(\n          \"Broadcast command is only supported in ClusterCommandExecutor\");\n    }\n    return ((ClusterCommandExecutor) executor).broadcastCommand(commandObject, true);\n  }\n\n  // ==================== Multi-Shard Command Methods ====================\n  // These methods execute commands across multiple Redis cluster shards when keys\n  // hash to different slots, aggregating the results appropriately.\n\n  private <T> T executeMultiShardCommand(List<CommandObject<T>> commandObjects) {\n    if (!(executor instanceof ClusterCommandExecutor)) {\n      throw new UnsupportedOperationException(\n          \"Multi-shard command is only supported in ClusterCommandExecutor\");\n    }\n    return ((ClusterCommandExecutor) executor).executeMultiShardCommand(commandObjects);\n  }\n\n  /**","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/RedisClusterClient.java#L267-L303","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the default ClusterCommandExecutor by building the client through the standard RedisClusterClient builder.","Guard with `client.getExecutor() instanceof ClusterCommandExecutor` (or instanceof on the client type) before calling broadcastCommand.","In non-cluster deployments, loop over the single connection/provider yourself instead of broadcasting."],"exampleFix":"// before\nclient.broadcastCommand(commandObjects.configSet(\"maxmemory\", \"1gb\"));\n\n// after\nif (executor instanceof ClusterCommandExecutor) {\n  client.broadcastCommand(commandObjects.configSet(\"maxmemory\", \"1gb\"));\n} else {\n  client.configSet(\"maxmemory\", \"1gb\");\n}","handlingStrategy":"try-catch","validationCode":"if (!(client instanceof RedisClusterClient)) {\n  throw new IllegalStateException(\"broadcastCommand requires a cluster client\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.broadcastCommand(cmd);\n} catch (UnsupportedOperationException e) {\n  // non-cluster executor: apply per-node instead\n  applySingleNode(cmd);\n}","preventionTips":["Use the standard builder so the default ClusterCommandExecutor is installed.","Document that broadcast APIs are cluster-only in your team's client wrappers.","Add a startup assertion that the executor type matches the APIs you call."],"tags":["unsupported-operation","cluster","broadcast"],"backgroundTag":"unsupported-operation","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}