1.编写lua脚本用于生成主键ID序列号,内容如下
local key = tostring(KEYS[1]);
local count = tonumber(KEYS[2]);
local dateStr = tostring(KEYS[3]);
local newKey = key .. "_" .. dateStr;
local numRedis = redis.call("incr", newKey);
print(numRedis);
if (numRedis == 1) then
redis.call("expire",newKey,60);
end
-- 计算数字的位数
local function DightNum(num)
if math.floor(num) ~= num or num < 0 then
return -1;
elseif 0 == num then
return 1;
else
local tmp_dight = 0;
while num > 0 do
num = math.floor(num/10);
tmp_dight = tmp_dight + 1;
end
return tmp_dight;
end
end
-- 在整数数字前面加0
-- dest_dight 标识最终生成位数,例如 AddZeroFrontNum(5, 1) 计算后是00001
local function AddZeroF