Path: blob/main/xml/en/docs/stream/ngx_stream_keyval_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Nginx, Inc.4-->56<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">78<module name="Module ngx_stream_keyval_module"9link="/en/docs/stream/ngx_stream_keyval_module.html"10lang="en"11rev="11">1213<section id="summary">1415<para>16The <literal>ngx_stream_keyval_module</literal> module (1.13.7) creates variables17with values taken from key-value pairs managed by the18<link doc="../http/ngx_http_api_module.xml" id="stream_keyvals_">API</link>19or a variable that can also be set with20<link url="https://github.com/nginx/njs-examples/">njs</link>.21</para>2223<para>24<note>25This module is available as part of our26<commercial_version>commercial subscription</commercial_version>.27</note>28</para>2930</section>313233<section id="example" name="Example Configuration">3435<para>36<example>37http {3839server {40...41location /api {42api write=on;43}44}45}4647stream {4849keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval;50keyval $ssl_server_name $name zone=one;5152server {53listen 12345 ssl;54proxy_pass $name;55ssl_certificate /usr/local/nginx/conf/cert.pem;56ssl_certificate_key /usr/local/nginx/conf/cert.key;57}58}59</example>60</para>6162</section>636465<section id="directives" name="Directives">6667<directive name="keyval">68<syntax>69<value>key</value>70<value>$variable</value>71<literal>zone</literal>=<value>name</value></syntax>72<default/>73<context>stream</context>7475<para>76Creates a new <value>$variable</value> whose value77is looked up by the <value>key</value> in the key-value database.78Matching rules are defined by the79<link id="keyval_type"><literal>type</literal></link> parameter of the80<link id="keyval_zone"><literal>keyval_zone</literal></link> directive.81The database is stored in a shared memory zone82specified by the <literal>zone</literal> parameter.83</para>8485</directive>868788<directive name="keyval_zone">89<syntax>90<literal>zone</literal>=<value>name</value>:<value>size</value>91[<literal>state</literal>=<value>file</value>]92[<literal>timeout</literal>=<value>time</value>]93[<literal>type</literal>=<literal>string</literal>|<literal>ip</literal>|<literal>prefix</literal>]94[<literal>sync</literal>]</syntax>95<default/>96<context>stream</context>9798<para>99Sets the <value>name</value> and <value>size</value> of the shared memory zone100that keeps the key-value database.101Key-value pairs are managed by the102<link doc="../http/ngx_http_api_module.xml" id="stream_keyvals_">API</link>.103</para>104105<para id="keyval_state">106The optional <literal>state</literal> parameter specifies a <value>file</value>107that keeps the current state of the key-value database in the JSON format108and makes it persistent across nginx restarts.109Changing the file content directly should be avoided.110</para>111112<para>113Examples:114<example>115keyval_zone zone=one:32k state=/var/lib/nginx/state/one.keyval; # path for Linux116keyval_zone zone=one:32k state=/var/db/nginx/state/one.keyval; # path for FreeBSD117</example>118</para>119120<para id="keyval_timeout">121The optional <literal>timeout</literal> parameter (1.15.0) sets122the time after which key-value pairs are removed from the zone.123</para>124125<para id="keyval_type">126The optional <literal>type</literal> parameter (1.17.1) activates127an extra index optimized for matching the key of a certain type128and defines matching rules when evaluating129a <link id="keyval">keyval</link> <literal>$variable</literal>.130<note>131The index is stored in the same shared memory zone132and thus requires additional storage.133</note>134135<list type="tag">136137<tag-name id="keyval_type_string"><literal>type=string</literal></tag-name>138<tag-desc>139default, no index is enabled;140variable lookup is performed using exact match141of the record key and a search key142</tag-desc>143144<tag-name id="keyval_type_ip"><literal>type=ip</literal></tag-name>145<tag-desc>146the search key is the textual representation of IPv4 or IPv6 address147or CIDR range;148to match a record key, the search key must belong to a subnet149specified by a record key or exactly match an IP address150</tag-desc>151152<tag-name id="keyval_type_prefix"><literal>type=prefix</literal></tag-name>153<tag-desc>154variable lookup is performed using prefix match155of a record key and a search key (1.17.5);156to match a record key, the record key must be a prefix of the search key157</tag-desc>158159</list>160</para>161162<para id="keyval_sync">163The optional <literal>sync</literal> parameter (1.15.0) enables164<link doc="ngx_stream_zone_sync_module.xml" id="zone_sync">synchronization</link>165of the shared memory zone.166The synchronization requires the167<literal>timeout</literal> parameter to be set.168<note>169If the synchronization is enabled, removal of key-value pairs (no matter170<link doc="../http/ngx_http_api_module.xml" id="patchStreamKeyvalZoneKeyValue">one</link>171or172<link doc="../http/ngx_http_api_module.xml" id="deleteStreamKeyvalZoneData">all</link>)173will be performed only on a target cluster node.174The same key-value pairs on other cluster nodes175will be removed upon <literal>timeout</literal>.176</note>177</para>178179</directive>180181</section>182183</module>184185186