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

相关推荐
yugi9878381 小时前
基于遗传算法优化主动悬架模糊控制的Matlab实现
开发语言·matlab
moxiaoran57532 小时前
Go语言的错误处理
开发语言·后端·golang
難釋懷2 小时前
Redis命令-Set命令
数据库·redis·缓存
编程小风筝2 小时前
Spring 框架如何整合Redis缓存中间件?
redis·spring·缓存
yugi9878382 小时前
MATLAB的多层感知器(MLP)与极限学习机(ELM)实现
开发语言·matlab
Never_Satisfied3 小时前
C#获取汉字拼音字母方法总结
开发语言·c#
zh_xuan3 小时前
kotlin 密封类
开发语言·kotlin
码小猿的CPP工坊3 小时前
C++软件开发之内存泄漏闭坑方法
开发语言·c++
Ethan-D3 小时前
#每日一题19 回溯 + 全排列思想
java·开发语言·python·算法·leetcode
满栀5853 小时前
分页插件制作
开发语言·前端·javascript·jquery