redisd.lua 574 Bytes
local skynet = require "skynet"
require "skynet.manager"
local redis = require "skynet.db.redis"

local db

local command = {}

function command.open(conf)
	db = redis.connect({
		host = conf.redishost,
		port = conf.redisport,
		db = conf.redisdb or 0,
		auth = conf.auth,
	})
end

skynet.start(function()
	skynet.dispatch("lua", function(session, address, cmd, ...)
		if cmd == "open" then
			local f = command[string.lower(cmd)]
			skynet.ret(skynet.pack(f(...)))
		else
			skynet.ret(skynet.pack(db[string.lower(cmd)](db, ...)))
		end
	end)
	skynet.register "REDIS"
end)