AMIMOTO で redis object cache を使用する

AMIMOTO で redis object cache を使用するには、以下の3ステップの作業が必要となります。

  1. redis をインストールする
  2. WordPress プラグイン Redis Object Cache をインストールして有効化する
  3. Redis Object Cache に関する不具合を修復するプラグインをインストールする

では、順番にやり方を説明しましょう。

redis をインストールする

これは、それほど難しくありません。

まず、SSH接続してから /opt/local/amimoto.json を編集してください。

以下のコマンドで対応可能です。

$ TMP_JSON=$(mktemp)
$ jq -s '.[1] * .[0]' <(echo '{"redis":true}') <(sudo cat /opt/local/amimoto.json) > ${TMP_JSON}
$ sudo mv -f ${TMP_JSON} /opt/local/amimoto.json

次に以下のコマンドを実行します。

$ sudo /opt/local/provision

 
Redis が起動しているかどうかは、以下のコマンドで確認できます。

$ sudo service redis status

Redis Object Cache をインストールして有効化する

まず、wp-config.php に以下のコードを追加しておきます。

/** Redis Cache Settings **/
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_MAXTTL', 3600);
define('WP_CACHE_KEY_SALT', DB_NAME);

設定する各定数の意味は、プラグインの説明読んでください。

プラグインのインストールを wp-cli 使ってやるなら、以下の通り

$ wp plugin install --activate redis-cache
$ wp redis enable
$ wp redis sttus
Status: Connected
Client: PECL Extension (v3.1.6)

Redis Object Cache に関する不具合を修復するプラグインをインストールする

ファイル redis-cache-fix.php を取ってきて、wp-content/mu-plugins/ ディレクトリに保存してください。
ターミナルでやるなら以下の通り

$ wget https://gist.githubusercontent.com/wokamoto/5c0c8a19a6dbd08e4121aa05d238543c/raw/464d418bcc7f9686852cdc3c0db6d6316278d6ed/redis-cache-fix.php
$ mkdir /path/to/wordpress/wp-content/mu-plugins
$ mv redis-cache-fix.php /path/to/wordpress/wp-content/mu-plugins/

こんな感じで良いかなと


Posted

in

by

Tags:

Comments

コメントを残す