http-redis2 #

Talks to Redis as an nginx upstream and sends raw Redis commands, including pipelined ones. Use it to read or write Redis from the config, often with srcache. For Lua code, upstream recommends lua-resty-redis instead.

Source: upstream source

Directives

redis2_bind #

syntax: redis2_bind 1 arg;  ·  context: http, server, location

Sets the local IP address for outgoing connections to the Redis upstream server.

redis2_buffer_size #

syntax: redis2_buffer_size 1 arg (size (k/m/g));  ·  context: http, server, location

Size in bytes; accepts k / m / g suffixes.

redis2_connect_timeout #

syntax: redis2_connect_timeout 1 arg (duration in ms);  ·  context: http, server, location

Such warnings might be rare but just be prepared for it. * You should tune the various timeout settings provided by this module like redis2_connect_timeout and redis2_read_timeout.

redis2_literal_raw_query #

syntax: redis2_literal_raw_query 1 arg (string);  ·  context: location, location-if

Here's some examples Note that in the second sample above, the set_unescape_uri directive is provided by the set-misc-nginx-module. Back to TOC redis2_literal_raw_query ------------------------ syntax: redis2_literal_raw_query QUERY default: no context: location, location if Specify a raw Redis query but Nginx variables in it will not be not recognized.

redis2_next_upstream #

syntax: redis2_next_upstream 1+ args (bitmask);  ·  context: http, server, location

This default size is the page size, may be 4k or 8k. Back to TOC redis2_next_upstream -------------------- syntax: redis2_next_upstream [ error | timeout | invalid_response | off ] default: error timeout context: http, server, location Specify which failure conditions should cause the request to be forwarded to another upstream server.

redis2_pass #

syntax: redis2_pass 1 arg;  ·  context: location, location-if

Applies only when the value in redis2_pass is an upstream with two or more servers.

redis2_query #

syntax: redis2_query 1+ args;  ·  context: location, location-if

So you can use them in redis2_query directives, for example, Back to TOC Lua Interoperability ==================== This module can be served as a non-blocking redis2 client for lua-nginx-module (but nowadays it is recommended to use the lua-resty-redis library instead, which is much simpler to use and more efficient most of the time).

redis2_raw_queries #

syntax: redis2_raw_queries 2 args;  ·  context: location, location-if

If you want to specify multiple pipelined commands in a single query, use the redis2_raw_queries directive instead. Back to TOC redis2_raw_queries ------------------ syntax: redis2_raw_queries N QUERIES default: no context: location, location if Specify N commands in the QUERIES argument.

redis2_raw_query #

syntax: redis2_raw_query 1 arg;  ·  context: location, location-if

For example, then GET /pipelined will yield two successive raw Redis responses while newlines here are actually CR LF (\r\n). Back to TOC redis2_raw_query ---------------- syntax: redis2_raw_query QUERY default: no context: location, location if Specify raw Redis queries and nginx variables are recognized in the QUERY argument.

redis2_read_timeout #

syntax: redis2_read_timeout 1 arg (duration in ms);  ·  context: http, server, location

Time units supported are s(seconds), ms(milliseconds), y(years), M(months), w(weeks), d(days), h(hours), and m(minutes). Back to TOC redis2_read_timeout ------------------- syntax: redis2_read_timeout <time> default: 60s context: http, server, location The timeout for reading TCP responses from the redis server, in seconds by default.

redis2_send_timeout #

syntax: redis2_send_timeout 1 arg (duration in ms);  ·  context: http, server, location

This time must be less than 597 hours. Back to TOC redis2_send_timeout ------------------- syntax: redis2_send_timeout <time> default: 60s context: http, server, location The timeout for sending TCP requests to the Redis server, in seconds by default.

Example


 location = /foo {
     set $value 'first';
     redis2_query set one $value;
     redis2_pass 127.0.0.1:6379;
 }

 # GET /get?key=some_key
 location = /get {
     set_unescape_uri $key $arg_key;  # this requires ngx_set_misc
     redis2_query get $key;
     redis2_pass foo.com:6379;
 }

 # GET /set?key=one&val=first%20value
 location = /set {
     set_unescape_uri $key $arg_key;  # this requires ngx_set_misc
     set_unescape_uri $val $arg_val;  # this requires ngx_set_misc
     redis2_query set $key $val;
     redis2_pass foo.com:6379;
 }

 # multiple pipelined queries
 location = /foo {
     set $value 'first';
     redis2_query set one $value;
     redis2_query get one;
     redis2_query set one two;
     redis2_query get one;
     redis2_pass 127.0.0.1:6379;
 }

 location = /bar {
     # $ is not special here...
     redis2_literal_raw_query '*1\r\n$4\r\nping\r\n';
     redis2_pass 127.0.0.1:6379;
 }

 location = /bar {
     # variables can be used below and $ is special
     redis2_raw_query 'get one\r\n';
     redis2_pass 127.0.0.1:6379;
 }

 # GET /baz?get%20foo%0d%0a
 location = /baz {
     set_unescape_uri $query $query_string; # this requires the ngx_set_misc module
     redis2_raw_query $query;
     redis2_pass 127.0.0.1:6379;
 }

 location = /init {
     redis2_query del key1;
     redis2_query lpush key1 C;
     redis2_query lpush key1 B;
     redis2_query lpush key1 A;
     redis2_pass 127.0.0.1:6379;
 }

 location = /get {
     redis2_query lrange key1 0 -1;
     redis2_pass 127.0.0.1:6379;
 }

↑ back to index