Redisson 分布式锁深入理解分析


package com.yc.puffer.serviceimpl.channel;

import com.alibaba.fastjson.JSONObject;

import com.yc.puffer.common.constant.GlobalConstants;

import com.yc.puffer.common.redis.global.ProductGlobal;

import com.yc.puffer.common.redis.global.RedisGlobal;

import com.yc.puffer.dao.mapper.BaseMapper;

import com.yc.puffer.dao.mapper.channel.ProductInfoMapper;

import com.yc.puffer.dao.model.channel.ProductInfo;

import com.yc.puffer.dao.model.channel.ProductInfoExample;

import com.yc.puffer.service.channel.ProductInfoService;

import com.yc.puffer.serviceimpl.BaseServiceImpl;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

/**

* @description:

* @author: haibin

* @create: 2019-08-09 15:01

*/

@Slf4j

@Service

@Transactional

public class ProductInfoServiceImplextends BaseServiceImplimplements ProductInfoService {

@Resource

private ProductInfoMapper productInfoMapper;

@Override

public BaseMapper getMapper() {

return productInfoMapper;

}

/**

* 初始化产品Key到Redis中

*/

    @Override

public void initProduct() {

log.info("初始化Product信息......start......");

ProductInfoExample example =new ProductInfoExample();

example.createCriteria().andStatusEqualTo(GlobalConstants.STATUS_ON);

List productInfos = productInfoMapper.selectByExample(example);

Map productMap =new HashMap<>();

productInfos.stream().forEach(productInfo -> {

productMap.put(productInfo.getId().toString(), JSONObject.toJSON(productInfo));

});

RedisGlobal global = ProductGlobal.getGlobal();

global.del();

global.set(productMap);

log.info("初始化Product信息......end......");

}

/**

* 根据产品ID获取产品信息

    * @param productId

    * @return

    */

    @Override

public ProductInfo queryProductInfoByProductId(Long productId) {

ProductInfoExample example =new ProductInfoExample();

example.createCriteria().andIdEqualTo(productId);

return this.selectSingleByExample(example);

}

}

你可能感兴趣的:(Redisson 分布式锁深入理解分析)