in jetcache-support/jetcache-redis/src/main/java/com/alicp/jetcache/redis/RedisCache.java [429:455]
private <C, P, R> R doWithPipeline(C client, boolean pipelineFirst, Function<P, R> function) {
C commands = null;
Closeable closeable = null;
try {
commands = client;
P pipeline = null;
// The connection from JedisPooled or JedisCluster needs to be returned to the pool.
if (commands instanceof JedisCluster) {
ClusterPipeline clusterPipeline = new ClusterPipeline(provider);
closeable = clusterPipeline;
pipeline = (P) clusterPipeline;
} else if (pipelineFirst) {
if (commands instanceof JedisPooled) {
Connection connection = ((JedisPooled) commands).getPool().getResource();
closeable = connection;
pipeline = (P) new Pipeline(connection);
} else if (commands instanceof Jedis) {
pipeline = (P) new Pipeline((Jedis) commands);
}
}
return function.apply(pipeline);
} finally {
closeJedis(commands);
close(closeable);
}
}