将连接池与Jedis一起使用

我在rest服务中使用Jedis连接redis服务器。

当我调用Web服务时,我想做jedis.hmgetjedis.exitshgetALL之类的操作

jedis.hmget("employee:data:" + emp_user_id, "employee_id").get(0); 

我用于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); } } 

我知道jedis不是线程安全的。当我一次使用1000个线程来调用服务时,我得到exception作为意外的流结束。 我开始知道jedis pool是线程安全但无法找到它的具体解决方案。

谢谢。 任何帮助,将不胜感激。

 JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", portno, 10000, "password"); https://github.com/xetorthio/jedis/wiki/Getting-started this link can resolve the problem 

查看Spring-data-redis

添加JedisConnectionFactory时,您将获得一个默认具有连接池function的connectionFactory。

JedisConnectionFactory()使用默认设置构造新的JedisConnectionFactory实例(默认连接池,没有分片信息)。 查看文档 。

    

有关详细信息, 请参阅文档 。