Abh*_*are 5 java multithreading connection-pooling jedis spring-boot
我正在使用 Jedis 连接 REST 服务中的 Redis 服务器。
当我调用 Web 服务时,我想做jedis.hmget、jedis.exits和hgetALL 之类的操作。
例如:
jedis.hmget("employee:data:" + emp_user_id, "employee_id").get(0);
Run Code Online (Sandbox Code Playgroud)
我用于 Redis 的配置是:
Jedis jedis;
JedisShardInfo shardInfo;
@PostConstruct
public void init() {
try {
shardInfo = new JedisShardInfo(Config.getRedisHost(), Config.getRedisPort());
shardInfo.setPassword(Config.getRedisPassword());
jedis = new Jedis(shardInfo);
jedis.select(2);
//jedis.se
} catch (Exception e) {
logger.error("Exception in init ------- > " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道 Jedis 不是线程安全的。当我同时使用 1000 个线程调用该服务时,我收到异常作为流的意外结束。我想知道 Jedis 池是线程安全的吗?无法为它找到特定的解决方案。
谢谢。任何帮助,将不胜感激。
小智 5
JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", portno, 10000,
"password");
Run Code Online (Sandbox Code Playgroud)
请参阅此处: https: //github.com/xetorthio/jedis/wiki/Getting-started