diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-02-28 11:10:50 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-02-28 11:10:56 +0800 |
commit | d77dc45e7eee74a7c39e850070103fcbbc8f38b0 (patch) | |
tree | 42ba2358aa53a99e30d7f493a619a40b67f9ec4a /openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua | |
parent | eba92f2ec4bd3783633fe2408eeae582b811c70a (diff) |
Support IP Hash LB policy
Issue-ID: MSB-154
Change-Id: I11b8e3a314c6045183971bf2207b9ccee7df10c2
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua')
-rw-r--r-- | openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua index 58d058c..8a69499 100644 --- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua +++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua @@ -1,6 +1,6 @@ --[[
- Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+ Copyright (C) 2018 ZTE, Inc. and others. All rights reserved. (ZTE)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ local cacheConf = msbConf.cacheConf local positive_ttl = cacheConf.positive_ttl or 60
local negative_ttl = cacheConf.negative_ttl or 2
local actualize_ttl = cacheConf.actualize_ttl or 120
+local stats_prefix = "monitor:stats:"
local svc_shcache = ngx.shared.svc_cache
@@ -120,4 +121,48 @@ local function load_customsvcnames(keypattern) end
_M.load_customsvcnames = load_customsvcnames
-return _M
\ No newline at end of file +
+function _M.save_reqnum_stats(date,info)
+ local _db = DB:new(options)
+ local c, err = _db:connectdb()
+ if not c then
+ return nil, err
+ end
+
+ local red = _db.redis
+ local resp,err = red:rpush(stats_prefix..date,info)
+ _db:keepalivedb()
+ if not resp then
+ return nil, "save_reqnum_stats failed! key:"..date.." value:"..info
+ else
+ return resp,nil
+ end
+end
+
+function _M.delete_reqnum_stats(date)
+ local _db = DB:new(options)
+ local c, err = _db:connectdb()
+ if not c then
+ return nil, err
+ end
+ local red = _db.redis
+ red:del(stats_prefix..date)
+ _db:keepalivedb()
+end
+
+function _M.get_reqnum_stats(date,latest_num)
+ if(type(latest_num)~="number") then
+ return nil,"the input num is illegal!"
+ end
+ local _db = DB:new(options)
+ local c, err = _db:connectdb()
+ if not c then
+ return nil, err
+ end
+ local red = _db.redis
+ local resp,err = red:lrange(stats_prefix..date,0-latest_num,-1)
+ _db:keepalivedb()
+ return resp,nil
+end
+
+return _M
|