|
@@ -44,6 +44,10 @@ function root:get_module_redis_key()
|
44
|
44
|
local moduleKey = string.format("mdl:%s:%s", self.mdlName, tostring(self:getKeyValue()))
|
45
|
45
|
return moduleKey
|
46
|
46
|
end
|
|
47
|
+-- 模块数据库表名
|
|
48
|
+function root:get_table_name()
|
|
49
|
+ return string.format("mdl_%s", tostring(self.mdlName))
|
|
50
|
+end
|
47
|
51
|
|
48
|
52
|
-- 获取玩家模块数据
|
49
|
53
|
function root:get_data_from_db()
|
|
@@ -54,8 +58,9 @@ function root:get_data_from_db()
|
54
|
58
|
end
|
55
|
59
|
|
56
|
60
|
if self.isSaveDB then
|
57
|
|
- local sql = sqlUtil.select_table_by_key(self.mdlName, self.keyName, self:getKeyValue())
|
|
61
|
+ local sql = sqlUtil.select_table_by_key(self:get_table_name(), self.keyName, self:getKeyValue())
|
58
|
62
|
res = lib_game_mysql:query(sql)
|
|
63
|
+ log.info("get_data_from_db sql[%s] res[%s]", tostring(sql), tostring(res))
|
59
|
64
|
if res and res[1] then
|
60
|
65
|
-- add to redis
|
61
|
66
|
redisUtil.hmset(moduleKey, res[1])
|
|
@@ -83,7 +88,7 @@ function root:get_column_db_value(column)
|
83
|
88
|
if is_empty(column) then
|
84
|
89
|
return
|
85
|
90
|
end
|
86
|
|
- local key = string.format("mdl:%s:%s", tostring(self.mdlName), tostring(self.uid))
|
|
91
|
+ local key = self:get_module_redis_key()
|
87
|
92
|
local val = lib_game_redis:hget(key, column)
|
88
|
93
|
if self:is_json(column) then
|
89
|
94
|
val = string.format("'%s'", cjson_encode(val))
|
|
@@ -108,10 +113,10 @@ function root:backup_to_db()
|
108
|
113
|
table.include(values, self:get_column_db_value(k))
|
109
|
114
|
end
|
110
|
115
|
|
111
|
|
- local tbName = string.format("mdl_%s", tostring(self.mdlName))
|
|
116
|
+ local tbName = self:get_table_name()
|
112
|
117
|
local sql =
|
113
|
118
|
string.format("replace into %s (%s) value (%s);", tbName, table.concat(colums, ","), table.concat(values, ","))
|
114
|
|
- lib_game_mysql:query(sql)
|
|
119
|
+ return lib_game_mysql:query(sql)
|
115
|
120
|
end
|
116
|
121
|
-- 删除模块热数据
|
117
|
122
|
function root:del_hot_data()
|