local EMAIL_LIMIT = KEYS[1] local roleId = KEYS[2] local emailId = KEYS[3] or 0 local createTime = KEYS[4] local contentPms = KEYS[5] or cmsgpack.pack({}) local rewardPms = KEYS[6] or cmsgpack.pack({}) local title = KEYS[7] or "" local stitle = KEYS[8] or "" local content = KEYS[9] or "" local attachments = KEYS[10] or "" -- local roleInfo = redis.call("HGET", string.format("role:%d", roleId), "delete") -- if tonumber(roleInfo) == 1 then return end local id = redis.call("HINCRBY", string.format("role:%d:autoincr", roleId), "email", 1) redis.call("LPUSH", string.format("role:%d:emailIds", roleId), id) local deleteIds = redis.call("LRANGE", string.format("role:%d:emailIds", roleId), EMAIL_LIMIT, -1) for _, deleteId in ipairs(deleteIds) do redis.call("DEL", string.format("email:%d:%d", roleId, deleteId)) end redis.call("LTRIM", string.format("role:%d:emailIds", roleId), 0, EMAIL_LIMIT - 1) redis.call("HMSET", string.format("email:%d:%d", roleId, id), "id", tostring(id), "emailId", emailId, "status", "0", "createtime", createTime, "contentPms", contentPms, "rewardPms", rewardPms, "title", title, "stitle", stitle, "content", content, "attachments", attachments )