Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openresty
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tangku7
openresty
Commits
bda0f7dc
Commit
bda0f7dc
authored
Nov 08, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use lua_shared_dict for cache instead
parent
05aa372f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
153 additions
and
17 deletions
+153
-17
nginx/conf/nginx.conf
nginx/conf/nginx.conf
+7
-3
nginx/lua/luabiz/doftp.lua
nginx/lua/luabiz/doftp.lua
+124
-0
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+7
-7
nginx/lua/luabiz/zx_base.lua
nginx/lua/luabiz/zx_base.lua
+4
-7
nginx/lua/luainit/db_conf.lua
nginx/lua/luainit/db_conf.lua
+8
-0
nginx/lua/luainit/init.lua
nginx/lua/luainit/init.lua
+3
-0
No files found.
nginx/conf/nginx.conf
View file @
bda0f7dc
...
@@ -31,14 +31,14 @@ http {
...
@@ -31,14 +31,14 @@ http {
#keepalive_timeout 0;
#keepalive_timeout 0;
keepalive_timeout
65
;
keepalive_timeout
65
;
lua_code_cache
on
;
lua_code_cache
on
;
lua_package_path
"/Users/zhoush/openresty/nginx/lua/?.lua
;
;
"
;
lua_package_path
"/Users/zhoush/openresty/nginx/lua/?.lua
;
;
"
;
init_by_lua_file
"lua/luainit/init.lua"
;
init_by_lua_file
"lua/luainit/init.lua"
;
init_worker_by_lua_file
"lua/luabiz/settle.lua"
;
init_worker_by_lua_file
"lua/luabiz/settle.lua"
;
# shared_dict 缓存
lua_shared_dict
dns_cache
128m
;
#gzip on;
#gzip on;
server
{
server
{
...
@@ -98,10 +98,14 @@ http {
...
@@ -98,10 +98,14 @@ http {
}
}
}
}
location
/csv
{
content_by_lua_file
"lua/luabiz/doftp.lua"
;
}
location
/get_addr
{
location
/get_addr
{
content_by_lua_block
{
content_by_lua_block
{
local
zx_base
=
_G.zx_base
or
loadmod("luabiz.zx_base")
local
zx_base
=
_G.zx_base
or
loadmod("luabiz.zx_base")
local
host
=
zx_base:_get_addr("
www.
baidu.com")
local
host
=
zx_base:_get_addr("baidu.com")
ngx.say(host)
ngx.say(host)
}
}
}
}
...
...
nginx/lua/luabiz/doftp.lua
0 → 100644
View file @
bda0f7dc
local
json
=
require
(
'cjson'
)
local
function
GetLines
(
filename
)
local
file
=
io.input
(
filename
)
local
res
=
{}
for
line
in
file
:
lines
()
do
table.insert
(
res
,
line
)
end
return
res
--returns number of lines and line table
end
local
function
getValues
(
str
)
local
idx
=
0
local
res
=
{}
if
str
~=
nil
then
while
string.find
(
str
,
","
)
~=
nil
do
local
i
,
j
=
string.find
(
str
,
","
);
idx
=
idx
+
1
;
res
[
idx
]
=
string.sub
(
str
,
1
,
j
-
1
);
str
=
string.sub
(
str
,
j
+
1
,
string.len
(
str
))
end
idx
=
idx
+
1
res
[
idx
]
=
str
end
return
idx
,
res
end
local
function
doLines
(
lines
)
local
vals
=
{}
for
i
=
1
,
#
lines
do
local
_
,
val
=
getValues
(
lines
[
i
])
table.insert
(
vals
,
val
)
end
return
vals
end
local
function
parseBasis
(
vals
)
local
res
=
{}
for
i
=
1
,
#
vals
do
local
line
=
{
user_sn
=
vals
[
i
][
1
],
user_name
=
vals
[
i
][
2
],
last_name
=
vals
[
i
][
3
],
first_name
=
vals
[
i
][
4
],
cmbc_hire_date
=
vals
[
i
][
5
],
name_pinin
=
vals
[
i
][
6
],
sex
=
vals
[
i
][
7
],
cmbc_oa_name
=
vals
[
i
][
8
],
birth_date
=
vals
[
i
][
9
],
folk
=
vals
[
i
][
10
],
user_email
=
vals
[
i
][
11
],
birth_country_code
=
vals
[
i
][
12
],
mobile
=
vals
[
i
][
13
],
telephone_number
=
vals
[
i
][
14
],
address
=
vals
[
i
][
15
],
city
=
vals
[
i
][
16
],
state
=
vals
[
i
][
17
],
address_postal
=
vals
[
i
][
18
],
dept_id
=
vals
[
i
][
19
],
id_info
=
vals
[
i
][
20
],
cmbc_user_status
=
vals
[
i
][
21
],
manageType
=
vals
[
i
][
22
],
user_type_id
=
vals
[
i
][
23
],
psn_jobinfo_order
=
vals
[
i
][
24
],
job_order
=
vals
[
i
][
25
]
}
res
[
i
]
=
line
end
return
res
end
local
function
parseHR_Org
(
vals
)
local
res
=
{}
for
i
=
1
,
#
vals
do
local
line
=
{
setid
=
vals
[
i
][
1
],
deptid
=
vals
[
i
][
2
],
org_name
=
vals
[
i
][
3
],
org_short_name
=
vals
[
i
][
4
],
effdt
=
vals
[
i
][
5
],
eff_status
=
vals
[
i
][
6
],
cmbc_dept_type
=
vals
[
i
][
7
],
parent_node_num
=
vals
[
i
][
8
],
parent_set_num
=
vals
[
i
][
9
],
company
=
vals
[
i
][
10
],
tree_level_num
=
vals
[
i
][
11
],
manageType
=
vals
[
i
][
12
],
org_order
=
vals
[
i
][
13
]
}
res
[
i
]
=
line
end
return
res
end
local
function
parseHR_job
(
vals
)
local
res
=
{}
for
i
=
1
,
#
vals
do
local
line
=
{
hr_position_code
=
vals
[
i
][
1
],
hr_position_name
=
vals
[
i
][
2
],
hr_position_short_name
=
vals
[
i
][
3
],
hr_position_job_code
=
vals
[
i
][
4
],
hr_position_set_id
=
vals
[
i
][
5
],
hr_position_dept_id
=
vals
[
i
][
6
],
hr_position_status
=
vals
[
i
][
7
],
hr_position_eff_date
=
vals
[
i
][
8
],
hr_position_eff_status
=
vals
[
i
][
9
],
manageType
=
vals
[
i
][
10
]
}
res
[
i
]
=
line
end
return
res
end
local
function
doftp
()
local
lines
=
GetLines
(
"/tmp/test.csv"
)
local
vals
=
doLines
(
lines
)
ngx
.
say
(
json
.
encode
(
vals
))
end
doftp
()
nginx/lua/luabiz/tk_sdt.lua
View file @
bda0f7dc
nginx/lua/luabiz/zx_base.lua
View file @
bda0f7dc
...
@@ -80,12 +80,11 @@ function ZX_BASE.date2time(self, date)
...
@@ -80,12 +80,11 @@ function ZX_BASE.date2time(self, date)
end
end
-- DNS Resolver
local
require
=
require
local
require
=
require
local
ngx_re_find
=
ngx
.
re
.
find
local
ngx_re_find
=
ngx
.
re
.
find
local
lrucache
=
require
"resty.lrucache"
local
resolver
=
require
"resty.dns.resolver"
local
resolver
=
require
"resty.dns.resolver"
local
cache_storage
=
lrucache
.
new
(
200
)
local
dns_cache
=
ngx
.
shared
.
dns_cache
local
function
_is_addr
(
hostname
)
local
function
_is_addr
(
hostname
)
return
ngx_re_find
(
hostname
,
[[\d+?\.\d+?\.\d+?\.\d+$]]
,
"jo"
)
return
ngx_re_find
(
hostname
,
[[\d+?\.\d+?\.\d+?\.\d+$]]
,
"jo"
)
...
@@ -98,8 +97,7 @@ function ZX_BASE._get_addr(self,hostname)
...
@@ -98,8 +97,7 @@ function ZX_BASE._get_addr(self,hostname)
return
hostname
,
hostname
return
hostname
,
hostname
end
end
local
addr
=
cache_storage
:
get
(
hostname
)
local
addr
=
dns_cache
:
get
(
hostname
)
if
addr
then
if
addr
then
return
addr
,
hostname
return
addr
,
hostname
end
end
...
@@ -115,14 +113,13 @@ function ZX_BASE._get_addr(self,hostname)
...
@@ -115,14 +113,13 @@ function ZX_BASE._get_addr(self,hostname)
end
end
local
answers
,
err
=
r
:
query
(
hostname
,
{
qtype
=
r
.
TYPE_A
})
local
answers
,
err
=
r
:
query
(
hostname
,
{
qtype
=
r
.
TYPE_A
})
if
not
answers
or
answers
.
errcode
then
if
not
answers
or
answers
.
errcode
then
return
nil
,
hostname
return
nil
,
hostname
end
end
for
i
,
ans
in
ipairs
(
answers
)
do
for
i
,
ans
in
ipairs
(
answers
)
do
if
ans
.
address
then
if
ans
.
address
then
cache_storag
e
:
set
(
hostname
,
ans
.
address
,
300
)
dns_cach
e
:
set
(
hostname
,
ans
.
address
,
300
)
return
ans
.
address
,
hostname
return
ans
.
address
,
hostname
end
end
end
end
...
...
nginx/lua/luainit/db_conf.lua
View file @
bda0f7dc
...
@@ -29,6 +29,14 @@ if hostname == "zzd-mer01" then -- 生产
...
@@ -29,6 +29,14 @@ if hostname == "zzd-mer01" then -- 生产
database
=
"tk_biz"
,
database
=
"tk_biz"
,
timeout
=
30
timeout
=
30
}
}
},
cmbc_card
=
{
host
=
"115.29.241.68"
,
user
=
"root"
,
password
=
"xingdata"
,
port
=
3306
,
database
=
"cmbc_card"
,
timeout
=
30
}
}
}
}
else
else
...
...
nginx/lua/luainit/init.lua
View file @
bda0f7dc
--- 定义NULL常量
--- 定义NULL常量
_G
.
NULL
=
ngx
.
null
_G
.
NULL
=
ngx
.
null
-- Get DNS Servers
local
pcall
=
pcall
local
pcall
=
pcall
local
io_open
=
io.open
local
io_open
=
io.open
local
ngx_re_gmatch
=
ngx
.
re
.
gmatch
local
ngx_re_gmatch
=
ngx
.
re
.
gmatch
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment