Git Product home page Git Product logo

miaosha's Introduction

高并发实现:

##用到的技术

##实现的模块

##集成redis:

1:添加redis依赖,添加Fastjson依赖(用于序列化)
2:加载redis配置文件(RedisConfig 使用@ConfigurationProperties来读取配置文件)
3:通过RedisConfig获取JedisPool池 吧JedisPool注入到spring容器中 供RedisService使用
4:为了防止多人开发项目下key被别人覆盖(同意使用前缀 不同模块使用不同的前缀 比如说用户模块使用用户模块的前缀)
>> 通过key封装结构:实现类-》抽象类-》接口
##两次MD5:

1:用户端:PASS=MD5(明文+固定+Salt)
2: 服务端:PASS=MD5(用户输入+随机Salt)

##JSR303参数校验+全局异常处理器

JSR303参数校验(自定义注解进行手机号格式验证)<br> 定义全局异常处理某一类异常从而能够减少代码重复率和复杂度(@ExceptionHandler)
@ExceptionHandler:统一处理某一类异常,从而能够减少代码重复率和复杂度
@ControllerAdvice:异常集中处理,更好的使业务逻辑与异常处理剥离开
@ResponseStatus:可以将某种异常映射为HTTP状态码

##redis分布式session:

通过UUIDUtil获取随机数作为token 吧唯一token作为用户的唯一标识符保存到redis中 通过Cookie吧token返回给客户端
通过重写WebMvcConfigurerAdapter下的方法 在进入到Controller前在redis中获取用户信息 这样减少代码的冗余 在需要用户信息的方法中注入用户实体类

##页面高并发优化

页面缓存
解决超卖(数据库增加唯一索引:防止用户重复购买,sql加库存数量判断:防止库存边负数)
秒杀静态化
对象缓存
##接口优化
Redis 预减库存减少对数据库访问
内存标记减少Redis
请求先入队缓冲(RabbitMQ) 异步下单 增强用户体验
nginx水平扩展
分库分表中间件(Mycat)
思路:减少数据库访问
1:系统初始化,吧商品库存数量加载到Redis
2:收到请求 Redis预减库存,库存不足,直接返回,否则进入3
3:请求入队,立即返回排队中
4:请求出队,生成订单,减少库存
5:客户端轮询,是否秒杀成功

miaosha's People

Contributors

dcg123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.