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

相关推荐
another heaven3 小时前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
SomeOtherTime4 小时前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain4 小时前
C++转Java日记(10)
java·开发语言
小林ixn5 小时前
别再全量塞历史了:用 Redis 给 Agent 装上「短期记忆」
redis·agent
总要学点什么5 小时前
第105篇:三维特效-流动图片墙体效果——让箭头沿墙长滚,它俩竟是同一份代码
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
xiaoye-duck5 小时前
《C++ 项目:手写大模型接入 SDK》会话模块整合:内存 SessionManager 与 DataManager 持久化联动
开发语言·数据库·c++·语言模型
寂寞的船6 小时前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
Funlang7 小时前
龙芯上的 Fun:从跑起来到机器码
开发语言·龙芯
总要学点什么7 小时前
第104篇:三维特效-流动墙体效果——让贴图沿墙流动,它却只肯走一条对角线
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
旖旎夜光7 小时前
【C++ 基础入门】C++11 新特性(中):右值引用、移动语义与完美转发
开发语言·c++·笔记·学习