nginx+lua+redis
文章内索引
[显示]
参考上篇nginx整合lua,继续为lua添加resty-redis模块,使lua可以连接redis。
1、下载resty-redis
https://github.com/openresty/lua-resty-redis
2、配置nginx
讲解压路径添加在nginx.conf的http中
1 |
lua_package_path "/usr/local/lua-resty-redis-master/lib/resty/redis.lua;;"; |
添加redis测试监听
1 2 3 4 5 |
location /lua_redis { default_type text/plain; content_by_lua_file /usr/local/lua_test/redis_test.lua; } |
编写redis通讯脚本
1 2 3 4 5 6 7 8 9 |
local redis = require "resty.redis" local cache = redis.new() cache.connect(cache, '192.168.29.206', '6379') local res = cache:get("foo") if res==ngx.null then ngx.say("This is Null") return end ngx.say(res) |
3、测试
访问http://192.168.29.120:8080/lua_redis
返回redis中key为foo的字符串huhanlin。
©版权声明:本文为【翰林小院】(huhanlin.com)原创文章,转载时请注明出处!
发表评论