Connecting my springboot application to the redis service on development (my system) works perfectly, but it wasn’t working when deployed to the server to run using docker compose.

It throws the error below;

Caused by: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool



The issue was related to a Redisconfiguration. Redis was expecting the IP to be running on localhost which wasn’t the case when I deployed it to the server, my applications were not running on localhost IP.

After carefully researching online, adding redis host and redis port to JedisConnectionFactory Bean fixed the issue.

public class SessionConfig extends AbstractHttpSessionApplicationInitializer {

private String REDIS_HOST;

private Integer REDIS_PORT;

public JedisConnectionFactory connectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(REDIS_HOST, REDIS_PORT);
return new JedisConnectionFactory(config);

public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>();
return template;