123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- local dataMode = require "dataMode"
- local lib_game_redis = require("lib_game_redis")
- local redisUtil = require("utils.redisUtil")
- local root = class("backupRole")
- -- 玩家key
- local function l_user_get_module_key(uid, mdl)
- if uid == nil or mdl == nil then
- return
- end
- return string.format("mdl:%s:%s", tostring(mdl), tostring(uid))
- end
- -- 角色构造
- function root:ctor(uid)
- local mapClass = dataMode.get_module_class_map()
- self.uid = uid
- self.moduleList = {}
- for _, moduleClass in pairs(mapClass) do
- local cname = moduleClass.__cname
- assert(self[cname] == nil)
- local moduleObj = moduleClass.new(uid)
- if moduleObj.isPersonal then
- self[cname] = moduleObj
- table.insert(self.moduleList, cname)
- end
- end
- end
- function root:isExist()
- if not self.user then
- return false
- end
- local key = l_user_get_module_key(self.uid, "user")
- return lib_game_redis:exists(key)
- end
- function root:getLoginTime()
- if not self.user then
- return
- end
- local key = l_user_get_module_key(self.uid, "user")
- return redisUtil.hget_int(key, "loginTime")
- end
- function root:backupToMysql()
- for _, cname in pairs(self.moduleList) do
- local moduleObj = self[cname]
- if moduleObj.isSaveDB then
- moduleObj:backup_to_db()
- end
- end
- end
- -- 重新载入模块数据
- function root:load_module_data(tabName)
- for _, cname in pairs(self.moduleList) do
- local moduleObj = self[cname]
- if moduleObj.tabName == tabName then
- moduleObj:get_data_from_db()
- end
- end
- end
- -- 删除玩家模块热数据
- function root:delRedisData()
- for _, cname in pairs(self.moduleList) do
- local moduleObj = self[cname]
- moduleObj:del_hot_data()
- end
- end
- return root
|