keyval_zone_redis

Defines a Redis zone for key-value storage used in NGINX configurations.

Syntaxkeyval_zone_redis zone=zone_name:SIZE;
Defaultnone
Contextstream
Arguments1+

Description

The keyval_zone_redis directive configures a Redis zone that can be utilized for storing key-value pairs within NGINX. This directive allows NGINX to interface with a Redis server, leveraging its capabilities as a fast key-value store. Users can define multiple Redis zones, which can be associated with key-value pairs in the configuration, enabling both storage and retrieval of data dynamically.

Parameters for this directive include the zone name and its specification, such as memory size if linking to a shared memory configuration or connection details for the Redis server. The directive is designed to operate within both HTTP and stream contexts, thus providing flexibility for various application architectures. The use of Redis as a backend allows for persistence of key-value data, cross-session access, and improved scalability, making it suitable for high-traffic scenarios.

When defining the zone, it is important to ensure that redis server details and connection parameters match the intended setup. This might include considerations for security, such as authentication credentials and network accessibility, as well as performance optimization for the Redis instance being used.

Config Example

stream {
    keyval_zone_redis zone=myredis:128k;
    keyval $remote_addr $text zone=myredis;

    server {
        listen 12345;

        location / {
            return 200 $text;
        }
    }
}

Ensure that the Redis server is reachable from the NGINX server, as network issues can prevent proper integration.

The Redis instance must be configured to allow connections from the NGINX worker processes for successful data retrieval and storage.

Pay close attention to the memory size specified in the zone; underestimating this can lead to key evictions during high load.

← Back to all directives