The ngx_http_keyval_module
module (1.13.3) creates variables with values taken from key-value pairs managed by the API or a variable (1.15.10) that can also be set with njs.
This module is available as part of our commercial subscription.
http { keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; keyval $arg_text $text zone=one; ... server { ... location / { return 200 $text; } location /api { api write=on; } } }
Syntax: | keyval
key
$variable
zone=name; |
---|---|
Default: | — |
Context: | http |
Creates a new $variable
whose value is looked up by the key
in the key-value database. Matching rules are defined by the type
parameter of the keyval_zone
directive. The database is stored in a shared memory zone specified by the zone
parameter.
Syntax: | keyval_zone
zone=name:size
[state=file]
[timeout=time]
[type=string|ip|prefix]
[sync]; |
---|---|
Default: | — |
Context: | http |
Sets the name
and size
of the shared memory zone that keeps the key-value database. Key-value pairs are managed by the API.
The optional state
parameter specifies a file
that keeps the current state of the key-value database in the JSON format and makes it persistent across nginx restarts.
Examples:
keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; # path for Linux keyval_zone zone=one:32k state=/var/db/nginx/state/one.keyval; # path for FreeBSD
The optional timeout
parameter (1.15.0) sets the time after which key-value pairs are removed from the zone.
The optional type
parameter (1.17.1) activates an extra index optimized for matching the key of a certain type and defines matching rules when evaluating a keyval $variable
.
The index is stored in the same shared memory zone and thus requires additional storage.
type=string
type=ip
type=prefix
The optional sync
parameter (1.15.0) enables synchronization of the shared memory zone. The synchronization requires the timeout
parameter to be set.
If the synchronization is enabled, removal of key-value pairs (no matter one or all) will be performed only on a target cluster node. The same key-value pairs on other cluster nodes will be removed upon timeout
.
© 2002-2020 Igor Sysoev
© 2011-2020 Nginx, Inc.
Licensed under the BSD License.
https://nginx.org/en/docs/http/ngx_http_keyval_module.html