{"record":{"id":"e3a7dd01b996f0d2","repo":"redis/jedis","slug":"unexpected-response-response","errorCode":null,"errorMessage":"Unexpected response: ${response}","messagePattern":"Unexpected response: (.+?)","errorType":"exception","errorClass":"JedisDataException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/MultiDbTransaction.java","lineNumber":154,"sourceCode":"    }\n  }\n\n  @Override\n  public final List<Object> exec() {\n    if (!inMulti) {\n      throw new IllegalStateException(\"EXEC without MULTI\");\n    }\n\n    boolean serverInMultiMode = false;\n    try {\n      Connection conn = acquireConnection();\n\n      Object multiReply = conn\n          .executeCommand(new CommandObject<>(new CommandArguments(MULTI), NO_OP_BUILDER));\n      if (!bytesEquals(OK_IN_BYTES, multiReply)) {\n        Object response = multiReply instanceof byte[] ? SafeEncoder.encode((byte[]) multiReply)\n            : multiReply;\n        throw new JedisDataException(\"Unexpected response: \" + response);\n      }\n\n      serverInMultiMode = true;\n\n      commands.forEach((command) -> conn.sendCommand(command.getKey()));\n      // following connection.getMany(int) flushes anyway, so no flush here.\n\n      // server replies QUEUED OR ERROR for each buffered command\n      List<Object> queuedCmdResponses = conn.getMany(commands.size());\n\n      if (!connectionSupplier.isActiveDatabase(initialDatabase)) {\n        JedisException dbSwitchException = new JedisException(\n            \"Active database has changed since transaction started\");\n        try {\n          conn.executeCommand(new CommandArguments(DISCARD));\n          serverInMultiMode = false;\n        } catch (Exception e) {\n          dbSwitchException.addSuppressed(e);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/MultiDbTransaction.java#L136-L172","documentation":"During exec(), MultiDbTransaction issues MULTI on the acquired connection and expects an 'OK' reply. If the server returns anything else (a Redis error like WRONGTYPE-encoded response, a proxy-injected error, or an unexpected object), it throws JedisDataException(\"Unexpected response: <reply>\") and aborts before sending the queued commands.","triggerScenarios":"The server replies to MULTI with something other than +OK — e.g. the connection is actually in an error state, a proxy/cluster intercepted MULTI, the connection was switched to a different database mid-transaction, or a previous error left the protocol stream misaligned.","commonSituations":"Failover replaced the underlying connection mid-transaction; running against a proxy (e.g. Redis Enterprise REST-managed endpoints) that rejects MULTI; stale connection after a network blip.","solutions":["Discard the transaction, obtain a fresh transaction/connection, and retry the whole multi()/commands/exec() cycle","Check server/proxy support for MULTI on the endpoint being used","Catch JedisDataException in exec() paths and log the raw reply to identify the server-side cause"],"exampleFix":"// before\nList<Object> res = transaction.exec(); // may throw on bad MULTI reply\n// after\ntry {\n  List<Object> res = transaction.exec();\n} catch (JedisDataException e) {\n  transaction.close();\n  transaction = client.transaction();\n  transaction.multi();\n  // re-issue commands and exec again\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { res = t.exec(); } catch (JedisDataException e) { t.close(); /* rebuild transaction and retry once */ }","preventionTips":["Ensure the endpoint supports MULTI/EXEC (beware proxies)","Use fresh connections/transactions after failover events","Log the unexpected reply text included in the exception for root-cause analysis"],"tags":["redis","transactions","protocol","unexpected-response"],"backgroundTag":"unexpected-response-shape","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"}