apisix lua插件使用redis

引入

local redis = require("resty.redis")

local red = redis:new()

local redis_config = {

host = "redis_v1",

port = "6379",

pass = "123456",

db = "0"

}

local function conn_redis()

local ok, err = red:connect(redis_config.host, redis_config.port)

if not ok then

core.log.error("failed to connect: ", err)

return false

end

local res, err = red:auth(redis_config.pass)

if not res then

core.log.error("failed to auth: ", err)

return false

end

local db, err = red:select(redis_config.db)

if not db then

core.log.error("failed to select: ", err, redis_config.db)

return false

end

return true

end

local function close_redis()

if not red then

return

end

-- 释放连接(连接池实现),毫秒

local pool_max_idle_time = 10000

-- 连接池大小

local pool_size = 100

local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)

if not ok then

core.log.error("redis red:set_keepalive err : ", err)

end

end

相关推荐
光泽雨3 小时前
C# 中 Assembly 类详解
开发语言·c#
少控科技3 小时前
C#基础训练营 - 02 - 运算器
开发语言·c#
Riemann~~4 小时前
C语言嵌入式风格
c语言·开发语言
zmzb01035 小时前
C++课后习题训练记录Day104
开发语言·c++
zmzb01036 小时前
C++课后习题训练记录Day105
开发语言·c++·算法
wjs20246 小时前
Vue3 条件语句
开发语言
_codemonster6 小时前
JavaWeb开发系列(六)JSP基础
java·开发语言
dinga198510266 小时前
linux上redis升级
linux·运维·redis
Web打印7 小时前
Phpask(php集成环境)之16 怎样彻底停用一个网站
开发语言·php
临水逸7 小时前
飞牛fnos 2025 漏洞Java跨域URL浏览器
java·开发语言·安全·web安全