{"record":{"id":"08236739a84302b6","repo":"redis/jedis","slug":"support-only-execute-to-replica-in-clustercommande","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/JedisCluster.java","lineNumber":501,"sourceCode":"            (ClusterCommandObjects) commandObjects,\n            commandFlagsRegistry,\n            executorService\n    );\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(\"Support only execute to replica in ClusterCommandExecutor\");\n    }\n    return ((ClusterCommandExecutor) executor).executeCommandToReplica(commandObject);\n  }\n}\n","sourceCodeStart":483,"sourceCodeEnd":506,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/JedisCluster.java#L483-L506","documentation":"executeCommandToReplica routes a command to a replica and only works when the client's CommandExecutor is a ClusterCommandExecutor. On any other executor type (simple, retry, multi-db, failover), it throws UnsupportedOperationException. This is a capability check guarding a cluster-only feature.","triggerScenarios":"Calling executeCommandToReplica(commandObject) on a UnifiedJedis (e.g. Jedis, RedisClient, MultiDbClient) whose executor is not a ClusterCommandExecutor.","commonSituations":"Shared utility code written for JedisCluster being reused with a standalone RedisClient; a client built via AbstractClientBuilder with the default non-cluster executor; refactoring that swapped the executor without updating replica-read call sites.","solutions":["Call executeCommandToReplica only on a cluster-based client (JedisCluster / RedisClusterClient with ClusterCommandExecutor)","For standalone clients use readFrom(ReadFrom.REPLICA) configuration or normal read commands instead","Check `executor instanceof ClusterCommandExecutor` (or client type) before invoking and provide a fallback path"],"exampleFix":"// before\nclient.executeCommandToReplica(commandObject); // UnsupportedOperationException on standalone\n// after\nif (client instanceof RedisClusterClient) {\n  client.executeCommandToReplica(commandObject);\n} else {\n  client.executeCommand(commandObject); // standard read path\n}","handlingStrategy":"type-guard","validationCode":"boolean replicaRoutingSupported = client instanceof RedisClusterClient || client instanceof JedisCluster;","typeGuard":"boolean supportsReplicaRead(UnifiedJedis client) { return client instanceof JedisCluster; }","tryCatchPattern":"try {\n  return client.executeCommandToReplica(cmd);\n} catch (UnsupportedOperationException e) {\n  return client.executeCommand(cmd); // fallback to normal read path\n}","preventionTips":["Only route replica reads on cluster clients","Configure ReadFrom.REPLICA on standalone clients that need replica reads","Keep cluster-only call sites separated from generic UnifiedJedis utilities"],"tags":["unsupported-operation","cluster","replica","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"}