This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new a82e31d chore: use the # operator to get the length of the Lua string
(#3716)
a82e31d is described below
commit a82e31d7e2df13a4687735b5064b0b56fb04ede1
Author: Yousa <[email protected]>
AuthorDate: Tue Mar 2 12:30:26 2021 +0800
chore: use the # operator to get the length of the Lua string (#3716)
You should always use the # operator to get the length of the Lua string
instead of the string.len
according to:
https://yousali.me/openresty-best-practices/lua/string_library.html
---
apisix/plugins/log-rotate.lua | 2 +-
apisix/plugins/proxy-cache.lua | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/apisix/plugins/log-rotate.lua b/apisix/plugins/log-rotate.lua
index 217c2f4..22709c2 100644
--- a/apisix/plugins/log-rotate.lua
+++ b/apisix/plugins/log-rotate.lua
@@ -61,7 +61,7 @@ local function get_last_index(str, key)
local _, idx = str_find(rev, key)
local n
if idx then
- n = string.len(rev) - idx + 1
+ n = #rev - idx + 1
end
return n
diff --git a/apisix/plugins/proxy-cache.lua b/apisix/plugins/proxy-cache.lua
index ccfa8a8..b3acbb0 100644
--- a/apisix/plugins/proxy-cache.lua
+++ b/apisix/plugins/proxy-cache.lua
@@ -194,7 +194,7 @@ local function generate_cache_filename(cache_path,
cache_levels, cache_key)
local levels = ngx_re.split(cache_levels, ":")
local filename = ""
- local index = string.len(md5sum)
+ local index = #md5sum
for k, v in pairs(levels) do
local length = tonumber(v)
index = index - length