12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- local M = {}
- local redisdbx = require "redisdbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local mysqldbx = require "mysqldbx"
- local cjson = require "cjson"
- function M.set(msg_body)
- local isok ,key = tools.checkData({"key","value"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- -- local current_time = os.date("%Y-%m-%d %H:%M:%S")
- redisdbx.exec("set",nil,"xs-"..msg_body.key,msg_body.value)
- return true, {}
- end
- function M.get(msg_body)
- local isok ,key = tools.checkData({"key"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local res = redisdbx.exec("get",nil,"xs-"..msg_body.key)
- return true, res
- end
- function M.db_set(msg_body)
- local isok ,key = tools.checkData({"key","value"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("SELECT * FROM data_manager WHERE db_key = '%s' LIMIT 1", msg_body.key)
- local isok,res;
- res = mysqldbx.query(sql)
- skynet.error("sql:",sql)
- if #res > 0 then
- sql = string.format("UPDATE data_manager SET db_value = '%s' WHERE db_key = '%s' ",cjson.encode(msg_body.value),msg_body.key)
- else
- sql = string.format("INSERT INTO `data_manager` (db_key,db_value) VALUES ('%s','%s')",msg_body.key,cjson.encode(msg_body.value))
- end
- skynet.error("sql:",sql)
- mysqldbx.query(sql)
- return true, {}
- end
- function M.db_get(msg_body)
- local isok ,key = tools.checkData({"key"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("SELECT * FROM data_manager WHERE db_key = '%s' LIMIT 1", msg_body.key)
- local isok,res;
- res = mysqldbx.query(sql)
- if #res > 0 then
- res = res[1]
- end
- return true, res
- end
- return M
|