Announcement Announcement Module
Collapse
No announcement yet.
Question aboout pipelining in Redis Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question aboout pipelining in Redis

    Hello

    How to use pipelining in Spring Data Key Value 1.0.0.M2? For example how to get someting like this in pipeline:
    RedisTemplate<String, Long> rt = new RedisTemplate<String, Long>(jedisConnection);
    rt.boundZSetOps("ordset1").rangeByScore(1, 5);
    rt.boundZSetOps("ordset2").rangeByScore(1, 5);
    rt.boundZSetOps("ordset3").rangeByScore(1, 5);

    I try many simple variants of code but allways after 4-8 request my page stop responding.

    This code return 0 result, after 4-8 gets app not responding:
    stringRedisTemplate.getConnectionFactory().getConn ection().openPipeline();
    stringRedisTemplate.boundValueOps("k1").get();
    stringRedisTemplate.boundValueOps("k2").get();
    stringRedisTemplate.boundValueOps("k3").get();
    stringRedisTemplate.boundValueOps("k4").get();
    List<Object> result = stringRedisTemplate.getConnectionFactory().getConn ection().closePipeline();
    logger.info(result.size());

    This code return 3 result, after 4-8 gets app not responding:
    JedisConnection jc = jedisConnection.getConnection();
    Pipeline p = jc.getNativeConnection().pipelined();
    p.get("k1");
    p.get("k2");
    p.get("k3");
    List<Object> results = p.execute();
    logger.info(results.size());


    Mayby close/execute pipeline remove connection from pool?

    This is my bean:
    <bean id="jedisConnection" class="org.springframework.data.keyvalue.redis.con nection.jedis.JedisConnectionFactory">
    <property name="hostName" value="192.168.10.124"/>
    <property name="port" value="6379"/>
    <property name="timeout" value="2000"/>
    <property name="usePool" value="true"></property> //disable this dont change anything
    </bean>

  • #2
    What's your Jedis version? In the current form, your code uses a different connection for each method - there's no scope to speak of.
    See Template.execute(RedisCallback, exposeConnection, pipeline) and execute(SessionCallback). By executing all the calls inside the same callback you are sure to use the same connection (and thus apply the settings to them).

    Additionally, you can get one connection and only use that rather then delegate to the template (which retrieves a new one each time).

    Note that the native jedis code should work as long as you close the connection. If you don't, then you're leaking connections.

    P.S. and please use [ c o d e ] tags to make the post readable.

    Comment

    Working...
    X