Home > Backend Development > PHP Tutorial > 如何用redis防并发,抢红包买东西这种并发

如何用redis防并发,抢红包买东西这种并发

WBOY
Release: 2016-06-20 12:40:38
Original
2614 people have browsed it

如何用redis防并发,抢红包买东西这种并发。最好能附代码 谢谢


回复讨论(解决方案)

原则是:先插入,后检查有效性

代码就不写了,不知道你的 redis 是否支持并发

原则是:先插入,后检查有效性

代码就不写了,不知道你的 redis 是否支持并发


支持并发。是这样的,先往redis插key,如果存在key就自增。然后把这个队列插入数据库。
还一种方式,抢购这种,先读缓存总数,然后递减
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template