0de80321
liuzujun
创建游戏数据库,role对应mys...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
local skynet = require "skynet"
require "utils.init"
local mysqld_count = tonumber(skynet.getenv("thread"))
local mysqld
skynet.init(function()
local idx = math.randomInt(1, mysqld_count)
mysqld = skynet.localname(".mysql" .. idx)
end)
local table_insert = table.insert
local mysqlproxy = {}
setmetatable(mysqlproxy, { __index = function(t, k)
local cmd = string.upper(k)
local f = function (self, ...)
if k == "query" then
--print(...)
end
local ok, result = pcall(skynet.call, mysqld, "lua", cmd, ...)
if not ok then
skynet.error(cmd, ..., "\n", debug.traceback(coroutine.running(), nil))
return
end
return result
end
t[k] = f
return f
end})
return mysqlproxy
|