栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

openresty 连接redis

openresty 连接redis

1 redis2 连接redis
location /luaredis {
    default_type text/html;
    set $value 'first';
	redis2_query set one $value;
	redis2_pass 127.0.0.1:6379;
}
2 lua-resty-redis访问redis

定义location

location /luaresty {
    default_type text/html;
    content_by_lua_file luaresty.lua;
}

lua 代码

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by hadoop.
--- DateTime: 2021/12/22 16:29
---

-- 引入redis包
local redis = require "resty.redis"
-- 进行初始化
local redisOb = redis:new()

local ok , err = redisOb:connect("127.0.0.1",6379)

if not ok then
    ngx.say("failed to connect ",err,"
") return end ok,err = redisOb:set("test","val1") if not ok then ngx.say("failed to set cat: ",err,"
") return end ngx.say("set result: ", ok,"
") local res,err = redisOb:get("test") if not ok then ngx.say("failed to get test: ",err,"
") return end if res == ngx.null then ngx.say("test not found.
") end ngx.say("test: ",res,"
")
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/676993.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号