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

相关推荐
军训猫猫头30 分钟前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
野蛮人6号40 分钟前
黑马点评系列问题之基础篇p7 06初识redis无法在虚拟机查到图形化界面存进去的键
redis·黑马点评
真的想上岸啊44 分钟前
学习C++、QT---18(C++ 记事本项目的stylesheet)
开发语言·c++·学习
明天好,会的1 小时前
跨平台ZeroMQ:在Rust中使用zmq库的完整指南
开发语言·后端·rust
丁劲犇2 小时前
用 Turbo Vision 2 为 Qt 6 控制台应用创建 TUI 字符 MainFrame
开发语言·c++·qt·tui·字符界面·curse
旷世奇才李先生2 小时前
Next.js 安装使用教程
开发语言·javascript·ecmascript
charlie1145141912 小时前
深入理解Qt的SetWindowsFlags函数
开发语言·c++·qt·原理分析
大春儿的试验田3 小时前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
likeGhee3 小时前
python缓存装饰器实现方案
开发语言·python·缓存
hqxstudying3 小时前
Redis为什么是单线程
java·redis