{"record":{"id":"e29693f7ff9afd46","repo":"redis/jedis","slug":"cannot-use-jedis-when-in-pipeline-please-use-pipe","errorCode":null,"errorMessage":"Cannot use Jedis when in Pipeline. Please use Pipeline or reset jedis state.","messagePattern":"Cannot use Jedis when in Pipeline\\. Please use Pipeline or reset jedis state\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/Jedis.java","lineNumber":434,"sourceCode":"      }\n    };\n    return transaction;\n  }\n\n  // Legacy\n  public Pipeline pipelined() {\n    pipeline = new Pipeline(this);\n    return pipeline;\n  }\n\n  // Legacy\n  protected void checkIsInMultiOrPipeline() {\n//    if (connection.isInMulti()) {\n    if (transaction != null) {\n      throw new IllegalStateException(\n          \"Cannot use Jedis when in Multi. Please use Transaction or reset jedis state.\");\n    } else if (pipeline != null && pipeline.hasPipelinedResponse()) {\n      throw new IllegalStateException(\n          \"Cannot use Jedis when in Pipeline. Please use Pipeline or reset jedis state.\");\n    }\n  }\n\n  public int getDB() {\n    return this.db;\n  }\n\n  /**\n   * @return <code>PONG</code>\n   */\n  @Override\n  public String ping() {\n    checkIsInMultiOrPipeline();\n    connection.sendCommand(Command.PING);\n    return connection.getStatusCodeReply();\n  }\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Jedis.java#L416-L452","documentation":"When a Jedis instance has pipelined commands whose responses have not been read back, direct commands on the instance would desynchronize request/response ordering. checkIsInMultiOrPipeline throws IllegalStateException when pipeline != null and hasPipelinedResponse() is true. You must sync the pipeline or reset state before issuing standalone commands.","triggerScenarios":"Calling ping/select/swapDB/flushDB/flushAll/copy (or any guarded command) on a Jedis after jedis.pipelined() was used and commands are still buffered (no sync/close yet).","commonSituations":"Interleaving administrative commands into a batch write loop that pipelines; exception paths that skip pipelining.sync() leaving responses pending; reusing a pooled Jedis instance that was returned with a live pipeline.","solutions":["Call pipeline.sync() (or syncAndReturnAll()) before issuing direct commands on jedis","Close the pipeline (try-with-resources on Pipeline) so state is cleaned on all paths","Call jedis.resetState() to discard pending pipelined responses if they are not needed","Use a separate connection from the pool for administrative commands"],"exampleFix":"// before\nPipeline p = jedis.pipelined();\np.set(\"k\", \"v\");\njedis.ping(); // IllegalStateException: in Pipeline\n// after\nPipeline p = jedis.pipelined();\np.set(\"k\", \"v\");\np.sync();\njedis.ping(); // OK","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  jedis.flushDB();\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Cannot use Jedis when in Pipeline\")) {\n    pipeline.sync();\n    jedis.flushDB();\n  } else throw e;\n}","preventionTips":["Always call pipeline.sync()/close() in a finally block or use try-with-resources","Do not interleave direct commands while a pipeline has buffered responses","Return pooled Jedis instances only after the pipeline is synced"],"tags":["pipeline","illegal-state","redis","buffered-commands"],"backgroundTag":"invalid-state-transition","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"}