Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions application/controller/WebSocketRedisController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if not wb then
return ngx.exit(444)
end


local push = function()
-- --create redis
local red = redis:new()
Expand All @@ -45,7 +46,7 @@ local push = function()

ok, err = red:auth(redis_auth)
if not ok then
log(ERR, "failed to auth: ", err)
ngx.log(ngx.ERR, "failed to auth: ", err)
wb:send_close()
end
--sub
Expand All @@ -61,7 +62,7 @@ local push = function()
local res, err = red:read_reply()
if res then
local item = res[3]
-- local bytes, err = wb:send_text(tostring(msg_id).." "..item)
--local bytes, err = wb:send_text(tostring(msg_id).." "..item)
local bytes, err = wb:send_text('[ '..tostring(msg_id).." ] "..ngx.localtime().." "..item)
if not bytes then
-- better error handling
Expand All @@ -73,6 +74,7 @@ local push = function()
end
end


local co = ngx.thread.spawn(push) -- create thread 1

--main loop
Expand Down
33 changes: 33 additions & 0 deletions application/demo/company_branch/cookie_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--
-- Created by IntelliJ IDEA.
-- User: Administrator
-- Date: 2017/6/19
-- Time: 10:05
-- To change this template use File | Settings | File Templates.
--
local redis = require "resty.redis"
local log = ngx.log
local redis_host = "121.41.88.209"
local redis_port = "63789"
local redis_auth = "tinywanredisamaistream"
local redis_timeout = 1000

local red = redis:new()
red:set_timeout(5000) -- 1 sec
local ok, err = red:connect(redis_host, redis_port)
if not ok then
ngx.log(ngx.ERR, "failed to connect redis: ", err)
wb:send_close()
return
end

ok, err = red:auth(redis_auth)
if not ok then
log(ERR, "failed to auth: ", err)
end

resp, err = red:set("LATEST_COMMENT::12345", "LATEST_COMMENT VALUES")
if not resp then
ngx.log(ngx.ERR, "set redis live error : ", err)
end

35 changes: 35 additions & 0 deletions application/demo/company_branch/header_filter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--
-- Created by IntelliJ IDEA.
-- User: Administrator
-- Date: 2017/6/19
-- Time: 10:14
-- To change this template use File | Settings | File Templates.
--
local match = string.match

local function get_cookies()
-- local cookies = ngx.header["Set-Cookie"] or {}
local cookies = ngx.header.set_cookie or {}
if type(cookies) == "string" then
cookies = {cookies}
end
return cookies
end

local function remove_cookie(cookie_name)
local cookies = get_cookies()

ngx.log(ngx.ERR, "source cookies ", table.concat(cookies, " "))
for key, value in ipairs(cookies) do
local name = match(value, "(.-)=")
ngx.log(ngx.ERR, key.."<=>", value)
if name == cookie_name then
table.remove(cookies, key)
end
end

ngx.header['Set-Cookie'] = cookies or {}
ngx.log(ngx.ERR, "new cookies ", table.concat(cookies, " "))
end

remove_cookie("Foo")
11 changes: 9 additions & 2 deletions conf/domains/nginx_demo.conf
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,15 @@ server {
}

#-------------------------------------------------cookie 的使用
location /cookie {

location ~ /header_add {
content_by_lua_block {
ngx.print(ngx.var.http_cookie)
is_internal = ngx.req.is_internal()
ngx.print(is_internal)
local request_time = ngx.now() - ngx.req.start_time()
ngx.print(request_time)
}
#header_filter_by_lua_file "${project_path}lua_project_v0.01/application/demo/company_branch/header_filter.lua";
}
}

4 changes: 2 additions & 2 deletions conf/domains/nginx_live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ server {
}

# 聊天室配置
location /live_chat_room {
location /live_redis {
lua_code_cache off;
content_by_lua_file "${project_path}lua_project_v0.01/application/controller/ChatRoomController.lua";
content_by_lua_file "${project_path}lua_project_v0.01/application/controller/test_redis.lua";
}


Expand Down
Empty file added logs/demo_error.log
Empty file.
Empty file added logs/index_error.log
Empty file.
99,407 changes: 99,407 additions & 0 deletions logs/live_error.log

Large diffs are not rendered by default.

Empty file added logs/product_access.log
Empty file.
Empty file added logs/product_error.log
Empty file.