Use Connection pool with Jedis

前端 未结 2 768
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 08:37

I am using Jedis to connect with a Redis server in a REST service.

When I am calling the web service I want to do operations like jedis.hmget ,

相关标签:
2条回答
  • 2021-01-06 09:09
    JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", portno, 10000,
                "password");
    

    See here: https://github.com/xetorthio/jedis/wiki/Getting-started

    0 讨论(0)
  • 2021-01-06 09:19

    Check out Spring-data-redis.

    When you add a JedisConnectionFactory you get a connectionFactory which has connection pooling capability by default.

    JedisConnectionFactory() Constructs a new JedisConnectionFactory instance with default settings (default connection pooling, no shard information). See docs.

    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true" p:host-name="server" p:port="6379"/>
    
    </beans>
    

    For further information, see the documentation.

    0 讨论(0)
提交回复
热议问题