redis+lua原子性扣除库存
·
if redis.call("exist",KEYS[1] == 1)
then
local productNum =tonumber(redis.call("get",KEYS[1]))
local subNum = tonumber(ARGV[1])
if(productNum <= 0)
then
return -4
end
if(subNum >= 0)
then
return -1
end
if(productNum + subNum >=0)
then
return redis.call("INCRBY",KYES[1],0 + subNum)
end
return -2
end
return -3
更多推荐



所有评论(0)