HTTP Redis

説明

このモジュールを簡単なキャッシュを実施するために使うことができます。近い将来にこのモジュールを拡張する計画があります。最新バージョンは https://people.freebsd.org/~osa/ngx_http_redis-0.3.9.tar.gz で利用可能です。

nginx 1.9.11 から、./configure コマンドライン上で、--add-module=PATH の代わりに--add-dynamic-module=PATH オプション を使って動的モジュールとしてこのモジュールをコンパイルすることができます。そして、load_module (httsp://nginx.org/en/docs/ngx_core_module.html#load_module) ディレクティブを使ってnginx.conf の中でモジュールを明示的にロードすることができます。

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]
デフォルト:-
コンテキスト:http, server, location

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

redis_bind

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

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

redis_connect_timeout

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

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

redis_read_timeout

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

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

redis_send_timeout

構文:redis_send_timeout [time]
デフォルト:redis_send_timeout 60000ms;
コンテキスト: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]
デフォルト:redis_next_upstream error timeout;
コンテキスト:http, server, location

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

redis_gzip_flag

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

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

変数

$redis_auth

redisの AUTH コマンドのためのPASSWORD値 (0.3.9から)。

$redis_db

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

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

$redis_key

redisキーの値。

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;
        }
    }
}

サポート

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

作者

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

参照

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