{"record":{"id":"ba10af853458b680","repo":"redis/jedis","slug":"support-only-execute-to-replica-in-clustercommande-ba10af","errorCode":null,"errorMessage":"Support only execute to replica in ClusterCommandExecutor","messagePattern":"Support only execute to replica in ClusterCommandExecutor","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/RedisClusterClient.java","lineNumber":266,"sourceCode":"            (ClusterConnectionProvider) provider,\n            (ClusterCommandObjects) commandObjects,\n            commandFlagsRegistry,\n            executorService\n    );\n  }\n  /**\n   * @param doMulti param\n   * @return nothing\n   * @throws UnsupportedOperationException\n   */\n  @Override\n  public AbstractTransaction transaction(boolean doMulti) {\n    throw new UnsupportedOperationException();\n  }\n\n  public final <T> T executeCommandToReplica(CommandObject<T> commandObject) {\n    if (!(executor instanceof ClusterCommandExecutor)) {\n      throw new UnsupportedOperationException(\n          \"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)) {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/RedisClusterClient.java#L248-L284","documentation":"RedisClusterClient.executeCommandToReplica() delegates replica routing to its internal CommandExecutor. Replica reads are only implemented by ClusterCommandExecutor; if the client was built with a different executor, the method throws UnsupportedOperationException rather than silently mis-routing the command. It is an explicit capability check on the configured executor.","triggerScenarios":"Calling executeCommandToReplica(commandObject) on a RedisClusterClient whose executor is not a ClusterCommandExecutor — e.g. after overriding the executor via a custom builder configuration or using a subclass that plugs in DefaultCommandExecutor/RetryCommandExecutor.","commonSituations":"Custom client builders or tests that substitute a non-cluster executor; code copied from a cluster setup into a standalone/single-node configuration; library-internal subclassing where validateSpecificConfiguration was bypassed.","solutions":["Build the client with the default RedisClusterClient builder so it uses ClusterCommandExecutor.","Remove the custom executor override (or the code path calling executeCommandToReplica) when not in cluster mode.","If you need replica reads in non-cluster mode, use an API supported by that executor instead."],"exampleFix":"// before\nRedisClusterClient client = RedisClusterClient.builder()\n    .executor(new RetryCommandExecutor(provider, cache))\n    .build();\nclient.executeCommandToReplica(cmdObj); // throws\n\n// after\nRedisClusterClient client = RedisClusterClient.builder()\n    .nodes(nodes)\n    .build(); // uses ClusterCommandExecutor\nclient.executeCommandToReplica(cmdObj);","handlingStrategy":"fallback","validationCode":"boolean supportsReplicaReads = client instanceof RedisClusterClient;\nif (!supportsReplicaReads) {\n  throw new IllegalStateException(\"Replica reads require RedisClusterClient\");\n}","typeGuard":"boolean canExecuteToReplica(RedisClusterClient c) {\n  return c != null; // replica routing requires the default cluster executor\n}","tryCatchPattern":"try {\n  return client.executeCommandToReplica(cmd);\n} catch (UnsupportedOperationException e) {\n  return client.sendCommand(cmd); // fallback to primary\n}","preventionTips":["Do not override the executor on RedisClusterClient unless you reimplement replica routing.","Keep replica-read call paths in cluster-only modules.","Run integration tests against a real cluster when using replica reads."],"tags":["unsupported-operation","cluster","executor"],"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"}