项目是有地址的,我会放到文章的最后面
- 直接service,我们会介绍两种秒杀模式
public interface GoodsService {
/**
* 通过lua脚本实现的秒杀
* @param skuCode 商品编码
* @param buyNum 购买数量
* @return 购买数量
*/
Long flashSellByLuaScript(String skuCode,int buyNum);
/**
* 通过redis 事务 实现的秒杀
* @param skuCode 商品编码
* @param buyNum 购买数量
* @return 购买数量
*/
Long flashSellByRedisWatch(String skuCode,int buyNum);
}
- service实现类
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.serializer.RedisSerializer;
import