HTTP Redis


You can use this module to perform simple caching. There are plans to extend this module in the near future. Latest version available at

Starting from nginx 1.9.11, it’s possible to compile this module as a dynamic module, by using the --add-dynamic-module=PATH option instead of --add-module=PATH on the ./configure command line. Then it’s possible to explicitly load the module in a nginx.conf via the load_module ( directive:

load_module /path/to/modules/;

Example configuration

server {
    location / {
        set $redis_key $uri;

        redis_pass     name:6379;
        default_type   text/html;
        error_page     404 = /fallback;

    location = /fallback {
        proxy_pass backend;



Syntax:redis_pass [name:port]
Context:http, server, location

The backend should set the data in redis. The redis key is /uri?args.


Syntax:redis_bind [addr]
Context:http, server, localtion

Use the following IP address as the source address for redis connections.


Syntax:redis_connect_timeout [time]
Default:redis_connect_timeout 60000ms;
Context:http, server, location

The timeout for connecting to redis, in milliseconds.


Syntax:redis_read_timeout [time]
Default:redis_read_timeout 60000ms;
Context:http, server, location

The timeout for reading from redis, in milliseconds.


Syntax:redis_send_timeout [time]
Default:redis_send_timeout 60000ms;
Context:http, server, location

The timeout for sending to redis, in milliseconds.


Syntax:redis_buffer_size [size]
Default:see getpagesize(2)
Context:http, server, location

The recv/send buffer size, in bytes.


Syntax:redis_next_upstream [error] [timeout] [invalid_response] [not_found] [off]
Default:redis_next_upstream error timeout;
Context:http, server, location

Which failure conditions should cause the request to be forwarded to another upstream server? Applies only when the value in redis_pass is an upstream with two or more servers.


Syntax:redis_gzip_flag [number]
Default:redis_gzip_flag unset;

Reimplementation of memcached_gzip_flag, see,34332,34463 for details.



The PASSWORD value for the redis AUTH command (since 0.3.9).


The number of redis database (required for < 0.3.4).

For ngx_http_redis >= 0.3.4 is not obligatory, default value is 0 if not defined.


The value of the redis key.

Keep-alive connections to redis servers

In 0.3.5 support of keep-alive connection backported from original ngx_http_memcached module of NGINX 1.1.4. For previous versions of NGINX you should use following instruction.

You need Maxim Dounin’s third party ngx_upstream_keepalive module together with this module for keep-alive TCP connections to your backend redis servers.

Here’s a sample configuration:

http {
    upstream redisbackend {

        # a pool with at most 1024 connections
        # and do not distinguish the servers:
        keepalive 1024 single;

    server {
        location /redis {
            redis_pass redisbackend;


Please use author’s email address for submit bug reports, patches and fixes.


Sergey A. Osokin <>

See also

  • Redis2 that implements almost the whole Redis 2.0 protocol.
  • SR Cache that can be used with this module to do transparent response caching for arbitrary NGINX locations.
  • The lua-resty-redis library for Lua.