废话不多说,想看详情看文章,直接上码,测效率
public void setProductPipeline(String redis的Key, List<集合类型> 集合名称) {
redisTemplate.executePipelined(new SessionCallback<Object>() {
@Override
@Nullable
public Object execute(RedisOperations operations) {
集合名称.forEach(element-> {
try {
operations.opsForZSet().add(redis的Key, element.getId(), element.getInsertDateTime.getTime());
} catch (ParseException e) {
log.error(e.getMessage());
}
});
long expire = RandomUtil.randomLong(RedisConstant.FIRST_MIN_REDIS_TIMEOUT, RedisConstant.FIRST_MAX_REDIS_TIMEOUT);
redisTemplate.expire(redisKey, expire, TimeUnit.HOURS);
return null;
}
});
}