--[[ Descripttion: version: Author: Neo,Huang Date: 2022-07-04 15:45:50 LastEditors: Neo,Huang LastEditTime: 2022-07-04 15:46:07 --]] local skynet = require "skynet" local snax = require "snax" local Mysql = { mysql_sup = nil, pool = nil } function Mysql:query(...) if not self.mysql_sup then self.mysql_sup = snax.queryservice("srvMysqlMgr") end if not self.pool or #self.pool == 0 then self.pool = {} -- get mysql pool local pool = self.mysql_sup.req.acquire(self.name) for k, v in ipairs(pool) do self.pool[k] = v end end if #self.pool == 0 then return end local db = self.pool[math.random(1, #self.pool)] return skynet.call(db, "lua", "query", ...) end function Mysql:new(name) local o = {} setmetatable(o, self) self.__index = self o.name = name return o end local root = {} local MYSQL = {} function root.get_mysql(name) local mysql = MYSQL[name] if mysql then return mysql end mysql = Mysql:new(name) MYSQL[name] = mysql return mysql end return root