Files
OMS/app/ome/lua/branch_store_set.lua
2025-12-28 23:13:25 +08:00

38 lines
816 B
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--[[
SKU仓库存缓存在REDIS通过LUA脚本重置库存和冻结实现原子性
@author: chenping@shopex.cn
@time: 2024-07-10
--]]
-- 更新库存函数
local function update(sku_id, fields)
-- 增加库存
return redis.call('HMSET', sku_id, unpack(fields))
end
-- 更新冻结
for i, v in ipairs(KEYS) do
local s = {}
-- 使用 gmatch 和正则表达式来拆分字符串
for piece in string.gmatch(ARGV[i], "[^,]+") do
table.insert(s, piece)
end
local fields = {}
table.insert(fields, 'store')
table.insert(fields, tonumber(s[1]))
table.insert(fields, 'store_freeze')
table.insert(fields, tonumber(s[2]))
local result = update(v, fields)
if not result then
return {300, 'FAIL_STOCK_IN_REDIS', v}
end
end
return {0, 'success'}