February 2018
Intermediate to advanced
382 pages
11h 33m
English
To understand Redis transactions, there is a scenario where we are going to organize a coupon codes seckilling, a quick sell out online, for a certain restaurant in Relp. There are only five coupon codes for this seckilling and we have a key, counts:seckilling, as a counter to hold the count of available coupon codes.
Here is the pseudo-code for this counter implementation:
//Initiate the count of coupon codes:
SET("counts:seckilling",5);
Start decreasing the counter:
WATCH("counts:seckilling");
count = GET("counts:seckilling");
MULTI();
if count > 0 then
DECR("counts:seckilling",1);
EXEC();
if ret != null then
print "Succeed!"
else
print "Failed!"
else
DISCARD();
print "Seckilling Over!"
Read now
Unlock full access