Skip to content

Commit

Permalink
推流、分发、节点、CDN智能查找
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinywan committed Mar 13, 2017
1 parent 2730b65 commit edcc99e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 24 additions & 6 deletions Lua-Nginx/redis-livenode/redis-livenode-streamid.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
-- 接受Nginx传递进来的参数$1 也就是SteamName
local stream_a = ngx.var.a

local redis = require("resty.redis");
-- 创建一个redis对象实例。在失败,返回nil和描述错误的字符串的情况下
local redis_instance = redis:new();
--设置后续操作的超时(以毫秒为单位)保护,包括connect方法
redis_instance:set_timeout(1000)
--建立连接
local ip = '127.0.0.1'
local port = 6379

--尝试连接到redis服务器正在侦听的远程主机和端口
local ok,err = redis_instance:connect(ip,port)
if not ok then
ngx.say("connect redis error : ",err)
return err
end
-- 接受Nginx传递进来的参数$1 也就是SteamName
local stream_id = ngx.var.a
local resp, err = redis_instance:get("msg")

-- 权限验证
local res,err = redis_instance:auth('tinywanredis')
if not res then
ngx.say("failed to authenticate: ", err)
return
end

--数据库选择
redis_instance:select(1)

--调用API获取数据
local resp, err = redis_instance:hget("liveNodeRedis:"..stream_a,'liveNode')
if not resp then
ngx.say("get msg error : ", err)
return err
end

--得到的数据为空处理
if resp == ngx.null then
ngx.say("this is not redis_data")
ngx.say("this is not redis_data") --比如默认值
return nil
end
ngx.var.stream_id = resp


ngx.say("reds get result : ", resp)
10 changes: 5 additions & 5 deletions Lua-Nginx/redis-livenode/set_by_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local redis_instance = redis:new();
--设置后续操作的超时(以毫秒为单位)保护,包括connect方法
redis_instance:set_timeout(1000)
--建立连接
local ip = '127.0.0.1'
local port = 6379
local ip = '121.41.88.209'
local port = 63789
--尝试连接到redis服务器正在侦听的远程主机和端口
local ok,err = redis_instance:connect(ip,port)
if not ok then
Expand All @@ -17,17 +17,17 @@ if not ok then
end

-- 权限验证
local res,err = redis_instance:auth('tinywanredis')
local res,err = redis_instance:auth('tinywanredisamaistream')
if not res then
ngx.say("failed to authenticate: ", err)
return
end

--数据库选择
redis_instance:select(1)
redis_instance:select(2)

--调用API获取数据
local resp, err = redis_instance:hget("liveNodeRedis:"..stream_a,'liveNode')
local resp, err = redis_instance:hget("StreamLiveNodeInnerIp:"..stream_a,'livenode')
if not resp then
ngx.say("get msg error : ", err)
return err
Expand Down

0 comments on commit edcc99e

Please sign in to comment.