同样的看redis组件
https://github.com/openresty/lua-resty-redis
按照实例添加redis.conf
worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { server { listen 8091; location / { default_type text/html; content_by_lua_block { local redis = require "resty.redis" local red = redis:new() red:set_timeout(1000) local ok,err = red:connect("127.0.0.1", 6379) if not ok then ngx.say("fail to connent", err) return end local res,err = red:get("lua") if not res then ngx.say("failed to get lua", err) return end ngx.say(res) } } } }
启动redis.conf配置
../nginx/sbin/nginx -p `pwd`/ -c conf/redis.conf
访问localhost:8091 获取了key为lua的数据,使用起来非常简单。