I have a jedisconfig written to connect to localhost hosted redis server:
public enum JedisConfig { INSTANCE; private final Logger LOGGER = LoggerFactory.getLogger(JedisConfig.class); private String host = AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("redis.host", "redis://:@localhost:6379/"); private String maxActive = AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("redis.maxActive", "2000"); private String maxIdle = AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("redis.maxIdle", "100"); private String maxWait = AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("redis.maxWait", "500"); private String minIdle = AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("redis.minIdle", "50"); private String password = "XXXXXXX"; JedisPool redisClient = null; public JedisPool getJedisPool() { if (redisClient == null) { synchronized (INSTANCE) { if (redisClient == null) { try { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(Integer.valueOf(maxActive)); config.setMaxIdle(Integer.valueOf(maxIdle)); config.setMinIdle(Integer.valueOf(minIdle)); config.setMaxWaitMillis(Integer.valueOf(maxWait)); config.setNumTestsPerEvictionRun(3); config.setTestOnBorrow(true); config.setTestOnReturn(true); config.setTestWhileIdle(true); config.setTimeBetweenEvictionRunsMillis(30000); config.setJmxEnabled(Boolean.valueOf(AppConfigManager.INSTANCE.getAppConfig().getProperties().getProperty("jedis.pool.jmx.monitoring", "false"))); URI jedisURI = new URI(host); redisClient = new JedisPool(config, jedisURI.getHost(), jedisURI.getPort(), redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password,Boolean.TRUE); } catch (URISyntaxException | NoSuchAlgorithmException | KeyManagementException e) { throw new RuntimeException("Redis couldn't be configured from URL :"+ host); } } } } return redisClient; }}
I am using the following health check function to ping the jedispool but I am getting the exception redis not connected.
private void checkRedisConnection(StringBuilder errorMessage) { JedisPool pool = JedisConfig.INSTANCE.getJedisPool(); try (Jedis jedis = pool.getResource()) { jedis.ping(); } catch (JedisConnectionException e) { errorMessage.append("Redis not connected"); } }
I was using stunnel earlier and here is the stunnel config:
#debug = 7#fips = no#output = /var/log/stunnel.log#pid = /var/run/stunnel.pid#setgid = root#setuid = root#sslVersion = TLSv1.2##[systemd]#accept = 127.0.0.1:6379#client = yes#connect = <ip>:6379
Now I have removed the stunnel, and i have changed redis.host to be the and other configuration in the properties file.But still I am not able to ping the redis server.
I tried to create a local redis host and still I am not able to connect to the redis server.Checked on internet as well but they are using redisstandalone configuration. Later I need to use ssl as well. The ssl functionality is provided by the jedis pool itself where we need to pass the boolean value to the function argument.