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

相关推荐
vivo互联网技术10 分钟前
号码生成系统的创新实践:游戏周周乐幸运码设计
redis·后端·架构
北方有星辰zz14 分钟前
数据结构:栈
java·开发语言·数据结构
都叫我大帅哥32 分钟前
Redis中zset内存变形记
java·redis
我是唐青枫37 分钟前
C#.NET NLog 详解
开发语言·c#·.net
大只鹅1 小时前
两级缓存 Caffeine + Redis 架构:原理、实现与实践
redis·缓存·架构
都叫我大帅哥1 小时前
Redis的ZSet:从“青铜”到“王者”的排序神器
java·redis
Mr_Xuhhh1 小时前
网络基础(1)
c语言·开发语言·网络·c++·qt·算法
小小霸王龙!1 小时前
互联网大厂Java面试实录:Spring Boot与微服务在电商场景中的应用
java·spring boot·redis·微服务·电商
旺旺大力包1 小时前
【JS笔记】JS 和 noodjs 的常见操作(十)
开发语言·javascript·node.js·ecmascript
都叫我大帅哥1 小时前
Redis BitMap 深度解剖:比特世界的精密引擎
redis