redis2_query

Sets a Redis command query to be executed by the upstream Redis server.

Syntaxredis2_query command [args];
Defaultnone
Contextlocation, if in location
Arguments1+

Description

The redis2_query directive allows you to define one or more Redis commands that will be sent to an upstream Redis server for execution. This directive can be used within location blocks, enabling specific handlers for different endpoints. The primary advantage of using redis2_query is its ability to convey Redis commands dynamically based on variables defined within the configuration. Multiple redis2_query instances can be declared, facilitating pipelined commands which can enhance performance by reducing the number of round trips to the Redis server.

Each redis2_query is evaluated at runtime, meaning you can pass in variables that were set earlier in the request processing cycle. This means you might use it in conjunction with other directives like set for dynamic values, or to fetch parameters from the query string. When combining multiple queries within the same location block, you can execute multiple Redis commands before finally using the redis2_pass directive to relay the queries to the specified Redis server. This provides flexibility and control over the Redis commands you execute in response to client requests.

Config Example

location = /store {
    set $item 'key';
    set $value 'value';
    redis2_query set $item $value;
    redis2_query get $item;
    redis2_pass 127.0.0.1:6379;
}

Ensure that variables used in the query are properly defined before the redis2_query directive is evaluated.

Using more than one redis2_query in a single location may lead to unexpected behavior or performance considerations, especially if not pipelined correctly.

Improper formatting of the Redis command or arguments can lead to errors or invalid commands being sent to the Redis server.

← Back to all directives