Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Solve the problem of redis seconds killing and overselling

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you to solve the redis spike oversold problem, I hope you read this article after the harvest, let us discuss it together!

First, generate inventory count

public function kucun() { //There are ten stocks $count=10; //add to redis list for($i=0;$ilpush('kucun',111111111); } self::dd(Predis::getInstance()->lrange('kucun',0,-1)); }

After the use of redis lpop or rpop to cut the list, before using llen or incr to judge the data, there will be oversold phenomenon, so here the use of lpop logic to solve the oversold problem

public function ru() { //judgment counter if (Predis::getInstance()->lpop('kucun')) { $user=User::where('user_id',1082)->find(); //Deposit Member ID Predis::getInstance()->lpush('user',$user['user_id']); //Counters accumulate by 1 // Predis::getInstance()->incr('number'); echo 'add kill successful'; exit(); }else{ echo 'activity as of'; exit(); } }

Test:

ab -r -n 1000 -c 1000 http://149.28.16.212/index/index/ru

After reading this article, I believe you have a certain understanding of solving the problem of redis spike oversold, want to know more related knowledge, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report