I have a use case to identify expired tokens stored in cache, so I implemented a method in the following way -
private Boolean isTokenExpired(long programId,String token,Jwt jwt){ try { if(!jedis.isConnected() || generalConfigHelper.getInt(REDIS_DB_INDEX) != jedis.getDB()){ jedis=redisHelper.getConnection(); jedis.select(generalConfigHelper.getInt(REDIS_DB_INDEX)); } Claims claims = (Claims) jwt.getBody(); //redis keys String tokenCacheKey=programId+":Tokens:"+token; String expiryTimeKey=programId+":InvalidateTokensBefore:"+claims.get("user_id"); List<String> values=jedis.mget(tokenCacheKey,expiryTimeKey); if (values.get(0)!=null){ return true; }else if (values.get(1)!=null){ log.info("redis: exp value:"+values.get(1)); long exp=Long.parseLong(claims.get("exp_ms")+""); return exp<Long.parseLong(values.get(1)+""); } } catch (Exception ex){ log.info("Error while reading from redis:"+ex); } finally { log.debug("Returning jedis instance to the pool"); redisHelper.closeConnection(jedis); } return false; }
The above code intially checks if client is connected to the resource pool and proceeds with select and mget commands, during the execution of these following commands I'm facing the following exceptions - SocketException: Broken pipe (Write failed) and SocketException: Socket is closed.
My Jedis Pool Configuration -maxTotal - 512maxIdle - 32minIdle - 8timeout - 10000 ms
Upon researching about these exceptions I found these GitHub issues which were highlighting these exceptions -https://github.com/mozilla/gcp-ingestion/issues/451https://github.com/redis/jedis/issues/185
The issues highlight about how the Redis Client timesout and breaks the connection therefore resulting in the following issues and made some recommendations for the timeout, I have followed the recommended config and still seem to face issues.