mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
@@ -146,10 +146,17 @@ local function compose_message(cmd, msg)
|
|||||||
return lines
|
return lines
|
||||||
end
|
end
|
||||||
|
|
||||||
local function redis_login(auth, db)
|
local function redis_login(conf)
|
||||||
|
local auth = conf.auth
|
||||||
|
local db = conf.db
|
||||||
if auth == nil and db == nil then
|
if auth == nil and db == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if auth then
|
||||||
|
if conf.username then
|
||||||
|
auth = { conf.username, auth }
|
||||||
|
end
|
||||||
|
end
|
||||||
return function(so)
|
return function(so)
|
||||||
if auth then
|
if auth then
|
||||||
so:request(compose_message("AUTH", auth), read_response)
|
so:request(compose_message("AUTH", auth), read_response)
|
||||||
@@ -164,7 +171,7 @@ function redis.connect(db_conf)
|
|||||||
local channel = socketchannel.channel {
|
local channel = socketchannel.channel {
|
||||||
host = db_conf.host,
|
host = db_conf.host,
|
||||||
port = db_conf.port or 6379,
|
port = db_conf.port or 6379,
|
||||||
auth = redis_login(db_conf.auth, db_conf.db),
|
auth = redis_login(db_conf),
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
overload = db_conf.overload,
|
overload = db_conf.overload,
|
||||||
}
|
}
|
||||||
@@ -256,10 +263,11 @@ local watchmeta = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function watch_login(obj, auth)
|
local function watch_login(conf, obj)
|
||||||
|
local login_auth = redis_login(conf)
|
||||||
return function(so)
|
return function(so)
|
||||||
if auth then
|
if login_auth then
|
||||||
so:request(compose_message("AUTH", auth), read_response)
|
login_auth(so)
|
||||||
end
|
end
|
||||||
for k in pairs(obj.__psubscribe) do
|
for k in pairs(obj.__psubscribe) do
|
||||||
so:request(compose_message ("PSUBSCRIBE", k))
|
so:request(compose_message ("PSUBSCRIBE", k))
|
||||||
@@ -278,7 +286,7 @@ function redis.watch(db_conf)
|
|||||||
local channel = socketchannel.channel {
|
local channel = socketchannel.channel {
|
||||||
host = db_conf.host,
|
host = db_conf.host,
|
||||||
port = db_conf.port or 6379,
|
port = db_conf.port or 6379,
|
||||||
auth = watch_login(obj, db_conf.auth),
|
auth = watch_login(db_conf, obj),
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
}
|
}
|
||||||
obj.__sock = channel
|
obj.__sock = channel
|
||||||
|
|||||||
Reference in New Issue
Block a user