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.
@Bean
public 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.
@Autowired
JedisPool jedisPool;
@Override
public String retrieve(String key) {
Jedis jedis = jedisPool.getResource();
String json = jedis.get(key);
jedis.close();
return json;
}
@Override
public 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?
尝试使用 http://localhost:6379 代替您当前的 URI
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.