redis2_raw_queries
The `redis2_raw_queries` directive allows the specification of multiple raw Redis commands to be sent to a Redis server.
Description
The redis2_raw_queries directive in NGINX is utilized within a location block to pass raw Redis protocol commands directly to the specified Redis server. This is particularly useful for sending complex or non-standard commands that may not be supported by the higher-level abstractions provided by other directives like redis2_query. The directive accepts two arguments: the first is the number of commands to process, and the second is a variable or literal that contains the actual Redis commands formatted in the Redis protocol style (with correct line endings and encoding). This raw command format allows for fine-grained control of the interactions with the Redis server, ensuring compatibility with existing Redis clients that may require specific command structures.
The typical use case for redis2_raw_queries involves scenarios where you are executing multiple commands or commands that require specific formatting, such as pipelined commands. It can help in optimizing performance by batching commands into a single request where applicable. This directive fits well in use cases such as implementing custom caching strategies or Redis Pub/Sub setups in web applications where standard query structures are insufficient. The directive's behavior is context-sensitive, functioning within location and if blocks, ensuring that the directives are executed in a sequential manner as dictated by any preceding configurations.
Config Example
location = /custom {
redis2_raw_queries 2 'set mykey value
get mykey
';
redis2_pass 127.0.0.1:6379;
}Ensure the raw Redis commands are correctly formatted according to the Redis protocol, especially with regards to line endings.
Using this directive without an appropriate redis2_pass may result in failed requests as there is no destination for the commands.
Be mindful of command size; overly large raw queries may lead to performance issues.