Search in sources :

Example 1 with ConnectResource

use of com.lcache.connect.ConnectResource in project lcache by long172066912.

the class AbstractLettuceHandleExecutor method pSync.

/**
 * Lettuce管道需要使用新的连接
 *
 * @param commands
 * @return
 */
@Override
public List<Object> pSync(List<PipelineCmd> commands) {
    // 设置使用方式为管道
    CacheConfigModel pipelineCacheConfigModel = new CacheConfigModel(this.getCacheConfigModel(), UseTypeEnum.PIPELINE);
    // 获取管道专用链接
    StatefulConnection statefulConnection = this.getStatefulConnection(new ConnectResource().setConnectResource(this.getPipelineConnectResource(pipelineCacheConfigModel)));
    try {
        List<Object> res = new ArrayList<>();
        List<RedisFuture<?>> redisFutures = new LettucePipelineExecutor(this.async(statefulConnection)).pSync(commands);
        for (int i = 0; i < redisFutures.size(); i++) {
            try {
                res.add(redisFutures.get(i).get());
            } catch (Exception e) {
                CacheExceptionFactory.addErrorLog("AbstractLettuceHandleExecutor->pSync get error ! size:" + i, e);
            }
        }
        return res;
    } finally {
    // 关闭连接
    // connectionResource.close();
    }
}
Also used : RedisFuture(io.lettuce.core.RedisFuture) StatefulConnection(io.lettuce.core.api.StatefulConnection) ArrayList(java.util.ArrayList) LettuceConnectResource(com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource) ConnectResource(com.lcache.connect.ConnectResource) LettucePipelineExecutor(com.lcache.extend.handle.redis.lettuce.pipeline.LettucePipelineExecutor) CacheConfigModel(com.lcache.core.model.CacheConfigModel)

Aggregations

ConnectResource (com.lcache.connect.ConnectResource)1 CacheConfigModel (com.lcache.core.model.CacheConfigModel)1 LettuceConnectResource (com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource)1 LettucePipelineExecutor (com.lcache.extend.handle.redis.lettuce.pipeline.LettucePipelineExecutor)1 RedisFuture (io.lettuce.core.RedisFuture)1 StatefulConnection (io.lettuce.core.api.StatefulConnection)1 ArrayList (java.util.ArrayList)1