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

相关推荐
虹科网络安全4 分钟前
艾体宝产品|深度解读 Redis 8.4 新增功能:原子化 Slot 迁移(上)
数据库·redis·bootstrap
Legendary_00829 分钟前
LDR6500:USB‑C DRP PD协议芯片技术详解与应用实践
c语言·开发语言
2301_800976931 小时前
正则表达式
开发语言·python·正则表达式
故事还在继续吗1 小时前
C++20关键特性
开发语言·c++·c++20
青少儿编程课堂2 小时前
2026青少儿信息素养大赛备赛指南!Python/Scratch/C++备考要点
开发语言·c++·python
AIFarmer2 小时前
【无标题】
开发语言·c++·算法
昇腾CANN2 小时前
TileLang-Ascend 算子性能优化方法与实操
开发语言·javascript·性能优化·昇腾·cann
沐知全栈开发3 小时前
ionic 手势事件详解
开发语言
lsx2024063 小时前
Bootstrap 按钮
开发语言
神仙别闹3 小时前
基于 Python 实现 BERT 的情感分析模型
开发语言·python·bert