Premise:
For openresty or Ngx_lua please refer to: http://openresty.org/en/
Problem:
When using Openresty to read data within Redis, Redis is not connected in init_by_lua_file, so sometimes it is only possible to read Redis data in the rewrite or access phase, and what is the way to read it during the initialization phase?
Workaround:
The method of invoking the shell command in the init phase is equivalent to executing a shell command in the init phase, reading the Redis data, parsing the read text data, which can be achieved by reading the Redis data into Nginx
Example:
1 There is a hash in Redis that stores data as:
Hmset Test_hash F1 v1 F2 v2 F3 v3
The code read in 2 Init_by_lua_file is:
Local cmd = "redis-cli hgetall test_hash"
local F = io.popen (cmd)
Local content = F:read ("*a")
F:close ()
Memory in the content above is the data in Redis.
Note that the content here is a string that needs to be re-parsed into a dictionary, can be stored in a variable, or can exist in shared memory.
The above describes a openresty in the init_by_lua_file phase of the method of reading Redis to shared memory, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.