{"record":{"id":"015fd02922d12303","repo":"quarkusio/quarkus","slug":"unable-to-add-command-to-the-current-transaction","errorCode":null,"errorMessage":"Unable to add command to the current transaction","messagePattern":"Unable to add command to the current transaction","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/datasource/AbstractTransactionalCommands.java","lineNumber":20,"sourceCode":"\nimport io.quarkus.redis.datasource.ReactiveTransactionalRedisCommands;\nimport io.quarkus.redis.datasource.transactions.ReactiveTransactionalRedisDataSource;\nimport io.vertx.redis.client.Response;\n\npublic class AbstractTransactionalCommands implements ReactiveTransactionalRedisCommands {\n\n    protected final TransactionHolder tx;\n    private final ReactiveTransactionalRedisDataSource ds;\n\n    public AbstractTransactionalCommands(ReactiveTransactionalRedisDataSource ds, TransactionHolder tx) {\n        this.ds = ds;\n        this.tx = tx;\n    }\n\n    protected void queuedOrDiscard(Response response) {\n        if (!\"QUEUED\".equals(response.toString())) {\n            this.tx.discard();\n            throw new IllegalStateException(\"Unable to add command to the current transaction\");\n        }\n    }\n\n    @Override\n    public ReactiveTransactionalRedisDataSource getDataSource() {\n        return ds;\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":29,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/datasource/AbstractTransactionalCommands.java#L2-L29","documentation":"In transactional Redis commands, each queued command must receive a 'QUEUED' reply. queuedOrDiscard() checks the response; if it is not QUEUED, the whole transaction is discarded and an IllegalStateException is thrown because the command could not be added to the transaction and continuing would leave the MULTI block inconsistent.","triggerScenarios":"Inside a Redis transaction (MULTI/EXEC flow via TransactionalRedisDataSource), a command is queued and the server responds with something other than QUEUED — e.g. a WRONGTYPE or syntax error reply during queueing.","commonSituations":"Calling a command with arguments of the wrong Redis type inside a transaction (e.g. LIST operation on a STRING key); using commands unsupported by the server version; connection issues mid-transaction.","solutions":["Inspect the discarded transaction's commands for type/key mismatches (WRONGTYPE replies) and fix the offending command.","Verify all commands used in the transaction are supported by your Redis server version.","Retry the transaction after the failure, since the client discarded it automatically."],"exampleFix":"// before\nTxRedisStringCommands<String> strings = tx.string();\nstrings.set(key, value); // fails if key holds a list -> WRONGTYPE\n\n// after\nif (tx.type(key).await().indefinitely().equals(\"string\")) {\n    tx.string().set(key, value);\n}","handlingStrategy":"try-catch","validationCode":"// Validate key types before entering the transaction\nString type = redis.key().type(key).await().indefinitely();","typeGuard":null,"tryCatchPattern":"try (TransactionResult ignored = txResult) {\n    tx.string().set(key, value);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Unable to add command to the current transaction\")) {\n        // transaction was discarded; inspect command args/types and retry\n    }\n}","preventionTips":["Ensure command data types match the actual key types inside transactions.","Only use commands supported by your Redis server version in MULTI blocks.","Log discarded transactions with their commands for diagnosis."],"tags":["redis","quarkus","transaction"],"backgroundTag":"redis-transaction-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}