openresty在set_by_lua_file階段操做redis

使用場景:按道理應該lua對應的階段均可以用此方法,init_by_lua_file、set_by_lua_file 其餘階段自行實驗redis

--思路:能夠在對應的lua腳本中調用shell命令,而後再shell命令中鏈接redis,以後就能夠操做redis了--
---eg: redis-cli -h 127.0.0.1 -p 6379 -a 123456 -n 1 get ${key}-----
----- -h(host)表示服務器, -p(port)表示端口, -a 表示密碼  -n 表明redis數據庫的db index,get 後面接的是對應的key--------
 local cmd = "redis-cli -h 192.168.1.13 -p 6379 -n 0 get service"
 local f = io.popen(cmd)

----獲取對應的數據---
 local redis_server = tostring(f:read())

--關閉---

f:close()
相關文章
相關標籤/搜索