redis2_literal_raw_query

The `redis2_literal_raw_query` directive allows for direct specification of raw Redis commands in NGINX configuration.

Syntaxredis2_literal_raw_query literal_string;
Defaultnone
Contextlocation, if in location
Arguments1

Description

The redis2_literal_raw_query directive is used in the context of NGINX's Redis upstream module to send a literal raw Redis command directly to the Redis server. This directive is unique in that it allows the administrator to bypass any variable interpolation by directly defining the exact Redis command, formatted as a string. This is particularly useful for commands that may require specific formatting or are not easily constructed using the other query directives provided by the module.

The directive accepts exactly one argument: the literal Redis command that is to be sent. It's important that this command is formatted properly according to the Redis protocol, which typically involves the use of Carriage Return and Line Feed (CRLF) to terminate commands. For example, a command like PING would need to be represented as *1\r\n$4\r\nping\r\n in its raw format. The directive must be placed within a location block or a conditional if statement inside a location block.

One common use case for redis2_literal_raw_query is when a user prefers to make a specific query that cannot be generated dynamically or would require excessive complexity if done through NGINX variables. By using this directive, administrators can ensure that the exact command sent to Redis is exactly as intended without any additional conversion or encoding that may occur when using other directives like redis2_query. Even though redis2_raw_query can accommodate variables for dynamic queries, situations that call for unaltered queries favor the use of redis2_literal_raw_query.

Config Example

location = /bar {
    redis2_literal_raw_query '*1\r\n$4\r\nping\r\n';
    redis2_pass 127.0.0.1:6379;
}

Ensure that the raw query is correctly formatted according to the Redis protocol to avoid errors.

Using CRLF correctly is crucial; failure to format the query properly will result in a failed request.

The string must not contain any variables, as this is meant to be a literal command.

← Back to all directives