spring redis executePipelined

Callback cannot return a non-null value as it gets overwritten by the pipeline.

报这个异常的原因是你在executePipelined中返回了一个非空值

源码:

public List executePipelined(final RedisCallback action, final RedisSerializer resultSerializer) {
    return execute(new RedisCallback>() {
        public List doInRedis(RedisConnection connection) throws DataAccessException {
            connection.openPipeline();
            boolean pipelinedClosed = false;
            try {
                Object result = action.doInRedis(connection);
                if (result != null) {
                    throw new InvalidDataAccessApiUsageException(
                            "Callback cannot return a non-null value as it gets overwritten by the pipeline");
                }
                List closePipeline = connection.closePipeline();
                pipelinedClosed = true;
                return deserializeMixedResults(closePipeline, resultSerializer, resultSerializer, resultSerializer);
            } finally {
                if (!pipelinedClosed) {
                    connection.closePipeline();
                }
            }
        }
    });
} 
  

由于所有redis操作会在connection.closePipeline()之后一并提交到redis并执行

如果不报这个错误的话,那么执行结果中,后一个结果会覆盖前一个结果造成错误。

你可能感兴趣的:(数据库,java,redis,spring,redis,java)