修复文件
This commit is contained in:
@@ -4,7 +4,13 @@
|
||||
-- 返回值:成功返回剩余库存,失败返回负数
|
||||
|
||||
local stock_key = KEYS[1]
|
||||
local quantity = tonumber(ARGV[1])
|
||||
local quantity_str = ARGV[1]
|
||||
local quantity = tonumber(quantity_str)
|
||||
|
||||
-- 检查quantity参数是否有效
|
||||
if quantity == nil or quantity <= 0 then
|
||||
return -3
|
||||
end
|
||||
|
||||
-- 获取当前库存
|
||||
local current_stock = redis.call('GET', stock_key)
|
||||
@@ -15,10 +21,15 @@ if current_stock == false then
|
||||
end
|
||||
|
||||
-- 转换为数字
|
||||
current_stock = tonumber(current_stock)
|
||||
local current_stock_num = tonumber(current_stock)
|
||||
|
||||
-- 检查转换是否成功
|
||||
if current_stock_num == nil then
|
||||
return -1
|
||||
end
|
||||
|
||||
-- 检查库存是否足够
|
||||
if current_stock < quantity then
|
||||
if current_stock_num < quantity then
|
||||
return -2
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user