java pipeline sync,通过Jedis Pipeline获取价值

I have a list of ids that I want to use to retrieve hashes from a Redis server using the java client jedis. As mentioned in the documentation, Jedis provides a way to use the pipeline by declaring Response objects and then sync the pipeline to get values:

Pipeline p = jedis.pipelined();

p.set("fool", "bar");

p.zadd("foo", 1, "barowitch"); p.zadd("foo", 0, "barinsky"); p.zadd("foo", 0, "barikoviev");

Response pipeString = p.get("fool");

Response> sose = p.zrange("foo", 0, -1);

p.sync();

However, my list has a variable length that keeps changing every few minutes. Thus, I am not able to predict the number of Response objects that I need to declare. Is there a way to get around that, something like:

Pipeline p = jedis.pipelined();

Response>> records;

for (int id: ids)

records.add(p.hgetAll(id))

p.sync();

解决方案

I guess what you want to achive is done like this.

List responses = new ArrayList<>();

Pipeline p = jedis.pipelined();

for (int id: ids) {

responses .add(p.get(id));

}

p.sync();

for(Reponse response : responses){

Object o = response.get();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值