HTTP Redis

説明

このモジュールを簡単なキャッシュを実施するために使うことができます。近い将来にこのモジュールを拡張する計画があります。Latest version available at http://people.FreeBSD.org/~osa/ngx_http_redis-0.3.8.tar.gz.

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 (http://nginx.org/en/docs/ngx_core_module.html#load_module) directive:

load_module /path/to/modules/ngx_http_redis_module.so;

設定例

server {
    location / {
        set $redis_key $uri;

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

    location = /fallback {
        proxy_pass backend;
    }
}

ディレクティブ

redis_pass

構文:redis_pass [name:port]
デフォルト:none
コンテキスト:http, server, location

バックエンドはredis内にデータを設定しなければなりません。redis キーは /uri?argsです。

redis_bind

構文:redis_bind [addr]
デフォルト:none
コンテキスト:http, server, localtion

以下のIPアドレスをredis接続のソースアドレスとして使用します。

redis_connect_timeout

構文:redis_connect_timeout [time]
デフォルト:60000
コンテキスト:http, server, location

redisへの接続のタイムアウトのミリ秒。

redis_read_timeout

構文:redis_read_timeout [time]
デフォルト:60000
コンテキスト:http, server, location

redisからの読み込みのタイムアウトのミリ秒。

redis_send_timeout

構文:redis_send_timeout [time]
デフォルト:60000
コンテキスト:http, server, location

redisへの送信のタイムアウトのミリ秒。

redis_buffer_size

構文:redis_buffer_size [size]
デフォルト:see getpagesize(2)
コンテキスト:http, server, location

recv/sendバッファサイズのバイト数。

redis_next_upstream

構文:redis_next_upstream [error] [timeout] [invalid_response] [not_found] [off]
デフォルト:error timeout
コンテキスト:http, server, location

どの失敗条件が他のupstreamサーバへの転送へのリクエストを発生させるべきか?redis_pass 内の値が2つ以上のサーバとのupstreamの場合のみ適用されます。

redis_gzip_flag

構文:redis_gzip_flag [number]
デフォルト:unset
コンテキスト:場所

memcached_gzip_flagの再実装。詳細はhttp://forum.nginx.org/read.php?29,34332,34463 を見てください。

変数

$redis_key

redisキーの値。

$redis_db

redisデータベースの数(0.3.4未満の場合に必須)・

ngx_http_redis >= 0.3.4 では義務ではありません。定義されていない場合のデフォルトの値は0 です。

redisサーバへのkeep-alive接続

0.3.5では、keep-alive接続のサポートがNGINX 1.1.4のオリジナルの ngx_http_memcached モジュールからバックポートされました。以前のNGINXのバージョンでは、以下の説明を使う必要があります。

backendのredisサーバへのkeep-alive TCP接続のために、このモジュールと一緒にMaxim Douninのサードパーティ ngx_upstream_keepaliveモジュールを必要とします。

以下は例の設定です:

http {
    upstream redisbackend {
        server 127.0.0.1:6379;

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

    server {
        ...
        location /redis {
            ...
            redis_pass redisbackend;
        }
    }
}

サポート

バグレポート、パッチおよび修正の提出には、著者のメールアドレスを使ってください。

Author

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

参照

  • Redis2 Redis2.0プロトコル全体のほとんどを実装。
  • SR Cache 任意のNGINX locationのために透過的な応答キャッシュを行うためにこのモジュールを使うことができます。
  • Luaのための lua-resty-redis ライブラリ。
TOP
inserted by FC2 system