Page Discussion History

Difference between revisions of "HttpRedis"

(See Also)
(See Also)
Line 141: Line 141:
= See Also =
= See Also =
* [[HttpRedis2Module]] for almost the whole Redis 2.0 protocol.
* [[HttpRedis2Module]] that implements almost the whole Redis 2.0 protocol.
* The [[http://github.com/agentzh/lua-resty-redis lua-resty-redis]] library for ngx_lua.
* [[HttpSRCacheModule]] that can be used with this module to do transparent response caching for arbitrary Nginx locations.
* The [http://github.com/agentzh/lua-resty-redis lua-resty-redis] library for ngx_lua.

Revision as of 08:51, 18 April 2012



Latest version available at http://people.FreeBSD.org/~osa/ngx_http_redis-0.3.6.tar.gz.


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

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 ]

default: none

context: http, server, location

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


syntax: redis_bind [ addr ]

default: none

context: http, server, localtion

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


syntax: redis_connect_timeout [ time ]

default: 60000

context: http, server, location

The timeout for connecting to redis, in milliseconds.


syntax: redis_read_timeout [ time ]

default: 60000

context: http, server, location

The timeout for reading from redis, in milliseconds.


syntax: redis_send_timeout [ time ]

default: 60000

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: 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: unset

context: location

Reimplementation of memcached_gzip_flag, see http://forum.nginx.org/read.php?29,34332,34463 for details.



The value of the redis key.


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.

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 e-mail address for submit bug reports, patches and fixes.


Sergey A. Osokin <osa@FreeBSD.ORG.ru>

See Also