I have a small spring boot application that I am trying to integrate with Redis using Jedis client.
I set up the Jedis pool to point towards a Redis docker container running locally.
@Beanpublic JedisPool jedisPool() { JedisPool jedisPool = null; try { URI redisUri = new URI("redis://localhost:6379"); jedisPool = new JedisPool(poolConfig(), redisUri, 20000, null, null, null); } catch (URISyntaxException e) { logger.error("Failed to create the redis pool: ", e); } return jedisPool;}
I have a RedisService
that makes use of the JedisPool
and perform transactions against the Redis Server.
@AutowiredJedisPool jedisPool;@Overridepublic String retrieve(String key) { Jedis jedis = jedisPool.getResource(); String json = jedis.get(key); jedis.close(); return json;}@Overridepublic void store(String key, String value) { Jedis jedis = jedisPool.getResource(); jedis.set(key, value); jedis.expire(key, keyExpire); jedis.close();}
When running the app I get this exception
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
I am able to connect to the Redis Server via redis-cli
but not from my spring boot app.
Any ideas on how to solve this issue?