upstream redis_pool {
server X.X.X.X:6379;
}
location /redis_hget {
set_unescape_uri $key $arg_key;
redis2_raw_query "hget $key\r\n";
redis2_pass redis_pool;
}
location /redis_get {
set_unescape_uri $key $arg_key;
redis2_raw_query "get $key\r\n";
location /vplay/queryMmsTotalPCount {
default_type 'text/plain';
content_by_lua '
local parser = require("redis.parser")
local pid = ngx.var.arg_pid
local mid = ngx.var.arg_mid
local vid = ngx.var.arg_vid
local platform = ngx.var.arg_platform
local callback = ngx.var.arg_callback
if not platform then
platform = 101
end
if platform == 0 then
platform = 101
end
local vp = 0
local vm = 0
local pscore = 0
local pcount = 0
local pcomm = 0
local vcomm = 0
local res = ""
if pid then
local vpid = string.format("%s%s %s","vp:",pid,platform)
local vpres = ngx.location.capture("/redis_hget",{args = {key=vpid}})
if vpres.status == 200 then
vp = parser.parse_reply(vpres.body)
if vp == nil then
vp = 0
end
end
local spid = string.format("%s%s s p nofield","sp:",pid)
local spres = ngx.location.capture("/redis_hmget",{args = {key=spid}})
if spres.status == 200 then
presult = parser.parse_reply(spres.body)
if presult then
pscore = presult[1]
pcount = presult[2]
if pscore == nil then
pscore = 0
end
if pcount == nil then
pcount = 0
end
end
end
local cpid = string.format("%s%s","pcomment:",pid)
local cpres = ngx.location.capture("/redis_get",{args = {key=cpid}})
if cpres.status == 200 then
pcomm = parser.parse_reply(cpres.body)
if pcomm == nil then
pcomm = 0
end
end
end
if mid then
mid = string.format("%s%s %s","vm:",mid,platform)
local vmres = ngx.location.capture("/redis_hget",{args = {key=mid}})
if vmres.status == 200 then
vm = parser.parse_reply(vmres.body)
if vm == nil then
vm = 0
end
end
end
if vid then
local cvid = string.format("%s%s","vcomment:",vid)
local cvres = ngx.location.capture("/redis_get",{args = {key=cvid}})
if cvres.status == 200 then
vcomm = parser.parse_reply(cvres.body)
if vcomm == nil then
vcomm = 0
end
end
end
if callback then
res = string.format("%s({%q:%s,%q:%s,%q:%s,%q:%s,%q:%s,%q:%s})",callback,"plist_play_count",vp,"media_play_count",vm,"plist_score",pscore,"plist_count"
,pcount,"vcomm_count",vcomm,"pcomm_count",pcomm)
else
res = string.format("{%q:%s,%q:%s,%q:%s,%q:%s,%q:%s,%q:%s}","plist_play_count",vp,"media_play_count",vm,"plist_score",pscore,"plist_count",pcount,"vcom
m_count",vcomm,"pcomm_count",pcomm)
end
ngx.say(res)
';
}