将连接池与Jedis一起使用 [英] Use Connection pool with Jedis
本文介绍了将连接池与Jedis一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jedis连接休息服务中的redis服务器。
I am using Jedis to connect with redis server in rest service.
当我调用web服务时我想做 jedis.hmget , jedis.exits 和 hgetALL 。
when I am calling web service I want to do operation like jedis.hmget , jedis.exits and hgetALL.
jedis.hmget("employee:data:" + emp_user_id, "employee_id").get(0);
我用于redis的配置是:
The configuration that I am using for redis is:
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);
}
}
我知道jedis不是线程当我一次使用1000个线程来调用服务时,我发现异常是因为意外的流结束。我开始知道jedis pool是线程安全但无法找到特定的解决方案。
I know that jedis is NOT thread safe.when I am using 1000 threads at once to call the service at that time I am getting exception as Unexpected end of stream. I came to know jedis pool is thread safe but unable to find specific solution for it.
谢谢。
任何帮助都将不胜感激。
Thanks. Any Help would be appreciated.
推荐答案
JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", portno, 10000,
"password");
https://github.com/xetorthio/jedis/wiki/Getting-started this link can resolve the problem
这篇关于将连接池与Jedis一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文