lua-resty-redis-fast
The repository of the binary installer
First, we need to configure the repository of the binary installer using the commands below. (The CLIENT_TOKEN
in the commands needs to be replaced with a valid Token from the subscription email)
curl -o get-xray-priv-lib-repo.sh https://pkg2.openresty.com/scripts/get-xray-priv-lib-repo.sh
sudo bash get-xray-priv-lib-repo.sh -l coro-nginx-module -t CLIENT_TOKEN
sudo bash get-xray-priv-lib-repo.sh -l lua-resty-redis-fast -t CLIENT_TOKEN
We also rely on Openresty’s open-source repositories in addition to the above-mentioned repository. If you have not previously configured the open-source repository, you can refer to this page for configurations.
Installation
For OpenResty-1.21.4.x
For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux
operating systems using yum
as the package manager, execute the following command to install the private libraries.
sudo yum install --disablerepo="*" --enablerepo="coro-nginx-module,lua-resty-redis-fast" -y lua-resty-redis-fast-1.21.4
For operating systems such as Fedora
that use dnf
as package manager, execute the following command to install the private library.
sudo dnf install --disablerepo="*" --enablerepo="coro-nginx-module,lua-resty-redis-fast" -y lua-resty-redis-fast-1.21.4
For operating systems such as Ubuntu/Debian
that use apt
as the package manager, run the following command to install the private libraries.
sudo apt-get install -y lua-resty-redis-fast-1.21.4
For OpenResty 1.25.3.x
For CentOS/RockyLinux/Amazon Linux/Alibaba Cloud Linux/Tecent Linux
operating systems using yum
as the package manager, execute the following command to install the private libraries.
sudo yum install --disablerepo="*" --enablerepo="coro-nginx-module,lua-resty-redis-fast" -y lua-resty-redis-fast-1.25.3
For operating systems such as Fedora
that use dnf
as package manager, execute the following command to install the private library.
sudo dnf install --disablerepo="*" --enablerepo="coro-nginx-module,lua-resty-redis-fast" -y lua-resty-redis-fast-1.25.3
For operating systems such as Ubuntu/Debian
that use apt
as the package manager, run the following command to install the private libraries.
sudo apt-get install -y lua-resty-redis-fast-1.25.3
Upgrade OpenResty
If openresty
has been previously installed, please execute the following upgrade command:
sudo yum upgrade -y openresty
Usage
Nginx configuration
Before you can use lua-resty-redis-fast
, you need to add the following configuration items to the configuration file nginx.conf
to load the related dynamic modules.
...
load_module "/usr/local/openresty-coro-nginx-module/lib/ngx_http_coro_module.so";
load_module "/usr/local/openresty-coro-nginx-module/lib/ngx_http_coro_hiredis_module.so";
http {
coro_preload /usr/local/openresty/openssl111/lib/libcrypto.so;
coro_preload /usr/local/openresty/openssl111/lib/libssl.so;
coro_preload /usr/local/openresty-plus/hiredis/lib/libhiredis.so;
coro_preload /usr/local/openresty-plus/hiredis/lib/libhiredis_ssl.so;
coro_stack_size 32768;
...
}
Lua interface
Interface set_keepalive
is changed. Other interfaces of this library are consistent with those of the open-source lua-resty-redis. Let’s see the following example:
load_module "/usr/local/openresty-coro-nginx-module/lib/ngx_http_coro_module.so";
load_module "/usr/local/openresty-coro-nginx-module/lib/ngx_http_coro_hiredis_module.so";
http {
coro_preload /usr/local/openresty-plus/hiredis/lib/libhiredis.so;
coro_stack_size 32768;
server {
location /test {
# need to specify the resolver to resolve the hostname
resolver 8.8.8.8;
content_by_lua_block {
local redis = require "resty.redis.fast"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
if not ok then
ngx.say("failed to connect: ", err)
return
end
ok, err = red:select(1)
if not ok then
ngx.say("failed to select: ", err)
return
end
local res, err = red:set("dog", "an animal")
if not res then
ngx.say("failed to set dog: ", err)
return
end
local ok, err = red:set_keepalive()
if not ok then
ngx.say("failed to set keepalive: ", err)
return
end
}
}
}
}