Set<String> range = jedis.zrange(rkeyCached, start, end);
if (range != null && range.size() > 0) {
count = jedis.zcard(rkeyCached);
result = Arrays.asList(range.toArray(new String[range.size()]));
} else {
Pipeline pipeline = shard.pipelined();
List<ConjunctiveFormula> dnf = DNF.convert(formulas);
for (ConjunctiveFormula conjunctiveFormula : dnf) {
String[] keys = conjunctiveFormula.getLiterals()
.toArray(
new String[conjunctiveFormula.getLiterals()
.size()]);
pipeline.zinterstore(tmpkey, zparams, keys);
pipeline.zunionstore(rkey, zparams, tmpkey, rkey);
}
if (order.equals(Order.ASC)) {
pipeline.zrange(rkey, start, end);
} else {
pipeline.zrevrange(rkey, start, end);
}
List<byte[]> rawresult = null;
if (cache == 0) {
pipeline.del(rkey, tmpkey);
List<Object> execute = pipeline.execute();
// get zrange or zrevrange result
rawresult = (List<byte[]>) execute.get(execute.size() - 2);
// get the last zunionstore output, which is the number of
// elements in the result
count = (Long) execute.get(execute.size() - 3);
} else {
pipeline.del(tmpkey);
pipeline.rename(rkey, rkeyCached);
pipeline.expire(rkeyCached, cache);
pipeline.del(rkey);
List<Object> execute = pipeline.execute();
// get zrange or zrevrange result
rawresult = (List<byte[]>) execute.get(execute.size() - 5);
// get the last zunionstore output, which is the number of
// elements in the result
count = (Long) execute.get(execute.size() - 6);