亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

redis的key或者計(jì)數(shù)器有沒有遞減的功能?
ringa_lee
ringa_lee 2017-04-21 11:17:22
0
3
834

比如現(xiàn)在想實(shí)現(xiàn)類似一個(gè)秒殺的功能,10個(gè)用戶搶2個(gè)商品,redis或者memcache或者其它的nosql產(chǎn)品,有沒有類似的功能,就是我有個(gè)計(jì)數(shù)器(庫(kù)存,比如等于2)然后,開始搶商品的時(shí)候,前2個(gè)用戶,已經(jīng)將庫(kù)存減到0了,當(dāng)?shù)?個(gè)人來?yè)尩臅r(shí)候,計(jì)數(shù)器不會(huì)變?yōu)?1,而是還是為0,并且這個(gè)操作會(huì)返回一個(gè)操作失敗,或者類似于mysql的返回影響行數(shù)為0的這種反饋信息,讓我知道的?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
迷茫

reids has DECR (atomic decrement), and memcache also has the decrement function. The difference between them is that when redis’s atomic decrement reaches 0, it will become a negative number, while memcache’s will always be 0

小葫蘆

No. It will become -1, I'm afraid you have to make your own judgment.

伊謝爾倫

Optimistic lock solution

Do not check the lock, pass it directly, but check the version number after passing it, and do not operate it correctly, otherwise roll back (requires transaction support)

One problem is that maybe users in orders 2 and 3 didn’t get it, but users in order 4 and 5 got it (in this case, you’ll know after you write a demo and test it)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template