5

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<String> pipeString = p.get("fool");
Response<Set<String>> 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<List<List<Map<String,String>>> records;
for (int id: ids)
    records.add(p.hgetAll(id))
p.sync();
addonis1990
  • 489
  • 1
  • 6
  • 17

1 Answers1

7

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

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();
}
techy
  • 331
  • 2
  • 12
FtoTheZ
  • 386
  • 3
  • 8