Java-高性能缓存Redis Lua 脚本
Redis LuacnaRedis Lua 脚本
(图片来源网络,侵删)
日期+ 自增Id(位数不足前面补零)
例:
日期:20210309 + 自增(5位)
2021030900001
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 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 AddZeroFrontNum(dest_dight, num) local num_dight = DightNum(num); if -1 == num_dight then return -1; elseif dest_dight
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。
还没有评论,来说两句吧...