【问题标题】:Getting values with jedis pipeline使用 jedis 管道获取值
【发布时间】:2015-05-29 19:57:54
【问题描述】:

我有一个 ID 列表,我想使用这些 ID 来使用 Java 客户端 jedis 从 Redis 服务器检索哈希。正如文档中提到的,Jedis 提供了一种使用管道的方法,通过声明 Response 对象然后同步管道来获取值:

Pipeline p = jedis.pipelined();
p.set("fool", "bar"); 
p.zadd("foo", 1, "barowitch");  p.zadd("foo", 0, "barinsky"); p.zadd("foo", 0, "barikoviev");
Response<String> pipeString = p.get("fool");
Response<Set<String>> sose = p.zrange("foo", 0, -1);
p.sync(); 

但是,我的列表的长度是可变的,每隔几分钟就会改变一次。因此,我无法预测需要声明的 Response 对象的数量。有没有办法解决这个问题,比如:

Pipeline p = jedis.pipelined();
Response<List<List<Map<String,String>>> records;
for (int id: ids)
    records.add(p.hgetAll(id))
p.sync();

【问题讨论】:

    标签: java redis pipeline jedis


    【解决方案1】:

    我猜你想要达到的目标是这样的。

    List<Response> 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();
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-11
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 2012-09-17
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多