{"record":{"id":"8ec41cc92e27714f","repo":"redis/jedis","slug":"status","errorCode":null,"errorMessage":"${status}","messagePattern":"\\$\\{status\\}","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/Connection.java","lineNumber":1113,"sourceCode":"\n  protected byte[] encodeToBytes(char[] chars) {\n    // Source: https://stackoverflow.com/a/9670279/4021802\n    ByteBuffer passBuf = Protocol.CHARSET.encode(CharBuffer.wrap(chars));\n    byte[] rawPass = Arrays.copyOfRange(passBuf.array(), passBuf.position(), passBuf.limit());\n    Arrays.fill(passBuf.array(), (byte) 0); // clear sensitive data\n    return rawPass;\n  }\n\n  public String select(final int index) {\n    sendCommand(Command.SELECT, Protocol.toByteArray(index));\n    return getStatusCodeReply();\n  }\n\n  public boolean ping() {\n    sendCommand(Command.PING);\n    String status = getStatusCodeReply();\n    if (!\"PONG\".equals(status)) {\n      throw new JedisException(status);\n    }\n    return true;\n  }\n\n  protected boolean isTokenBasedAuthenticationEnabled() {\n    return authXManager != null;\n  }\n\n  protected AuthXManager getAuthXManager() {\n    return authXManager;\n  }\n\n  /**\n   * Returns an unmodifiable view of the registered push consumers.\n   *\n   * @return the list of push consumers\n   */\n  List<PushConsumer> getPushConsumers() {","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Connection.java#L1095-L1131","documentation":"Connection.ping() sends the PING command and throws JedisException carrying the raw status reply when the server does not answer exactly 'PONG'. The exception message is the server's actual status response, so the text varies with the reply received.","triggerScenarios":"Calling ping() on a Connection whose server or intermediate layer answers PING with something other than the status reply 'PONG' (e.g. a different message, an error string surfaced as status, or a proxy reply).","commonSituations":"Health-check code against Redis behind proxies/LBs that rewrite PING responses; connecting to a non-Redis service on the port; custom protocol/handshake states where the previous command's reply is still queued so PING reads a stale reply.","solutions":["Check what the exception message says — it is the literal reply the server returned","Verify the endpoint is actually a Redis server responding to PING with PONG","Drain pending replies / ensure no unsynced pipeline before calling ping()","Prefer client.ping() or the pool's built-in health checks instead of raw connection.ping()"],"exampleFix":"// before\nboolean ok = connection.ping();\n// after\ntry {\n  boolean ok = connection.ping();\n} catch (JedisException e) {\n  log.warn(\"PING failed with reply: {}\", e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"// no pre-call check possible; validate endpoint reachability instead\nSocket s = new Socket(host, port); // ensure a Redis server, not another service, is listening","typeGuard":null,"tryCatchPattern":"try {\n  boolean ok = connection.ping();\n} catch (JedisException e) {\n  log.warn(\"PING returned unexpected reply: {}\", e.getMessage());\n}","preventionTips":["Use high-level client health checks (client.ping()) instead of raw connection.ping()","Ensure the pipeline is drained before calling ping() so no stale reply is read","Confirm the host:port points at Redis and not a proxy that rewrites PING"],"tags":["java","jedis","ping","health-check","unexpected-response"],"backgroundTag":"unexpected-api-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"}