local md5_str = get_str_md5(q_query)if md5_str == null thenreturnend
function get_str_md5(input_s)local resty_md5 = require "resty.md5"local md5 = resty_md5:new()if not md5 thenngx.log(ngx.ERR, "failed to create md5 object")returnendlocal ok = md5:update(input_s)if not ok thenngx.log(ngx.ERR, "failed to add data")returnendlocal digest = md5:final()local str = require "resty.string"local md5_str = str.to_hex(digest)return md5_str
end
根据md5去redis中query
local redis_query_key ="hke:heavy_expr:".. md5_str--ngx.log(ngx.ERR, "redis_query_key: ",redis_query_key)local redis_get_res = redis_get(redis_query_key)if redis_get_res ==truethenq_query = redis_query_keyend
function redis_get(key)-- start of redislocal redis = require "resty.redis"local red = redis:new()--red:set_timeouts(1000, 1000, 1000)local ok, conn_err = red:connect("localhost", 6379)if not ok thenngx.log(ngx.ERR, "[redis]failed to connect redis server:", conn_err)returnfalseendlocal res, get_err = red:get(key)if get_err thenngx.log(ngx.ERR, "[redis]failed to get value by key: ", key, "err:", get_err)returnfalseendred:set_keepalive(30000, 1000)if res ~= ngx.null thenngx.log(ngx.INFO, "[redis]success get value by key: ", key, "value: ", res)returntrueelsereturnfalseend-- end of redis
end
1.翻转字符串 let str abcdef str str.split().reverse().join() console.log(str) 因此想到了我之前写的截取字符串获取参数跳转,在写一遍 let str nameJack&age18&gender男 let list str.split(&); let obj {} list.forEach((v)>{ …