2.14.1.2.5. Setting up Redis in WordPress

For use Redis in WordPress, you need to install and configure one of the specialized plugins.

  1. Install and activate the plugin Redis Object Cache.
  2. Edit site config file wp-config.php and add to its beginning right after <?php such lines (in the second line instead of example substitute hosting account name, in which the site is located, in the third — instead of example substitute a unique prefix for storing data in Redis, which is important when using Redis for multiple sites):
    define('WP_REDIS_SCHEME', 'unix');
    define('WP_REDIS_PATH', '/home/example/.system/redis.sock');
    define('WP_CACHE_KEY_SALT', 'example');
  3. In the admin panel of the site, go to the section «Settings → Redis» and press «Enable Object Cache»:If everything is in order, at the top of the section in the line «Condition» should display «Connected»:
  4. Check the site is working.
  1. Install and activate the plugin W3 Total Cache.
  2. Go to section «Performance → General Settings»:
  3. In the block «Object Cache»:
    1. In line «Object Cache» turnon «Enabled».
    2. In line «Object Cache Method» choose «Redis».
    3. Save your changes.
  4. Go to section «Performance → Object Cache»:
  5. In the block «Advanced»:
    1. In field «Redis hostname:port / IP:port» indicate /home/example/.system/redis.sock (insteadof example substitute hosting account namewhere the site is located) and click «Test»:If everything is in order, a green inscription should be displayed «Test passed»:
    2. Save your changes.
  6. Follow the same steps for «Page Cache» and «Database Cache».
  7. Check the site is working.

Paid plugin

You can purchase a license for official website.
  1. Install and activate the Object Cache Pro plugin (installation is performed either by downloading the archive with the plugin through the WordPress admin panel, or by manually placing the plugin directory in the WordPress plugin directory).
  2. Place the plugin directory in the WordPress plugins directory.
  3. Edit site config file wp-config.php and add lines like this to it (in the second line, instead of <your-license-token> substitute your license token, in the third line — instead of example substitute hosting account namewhere the site is hosted):
    define('WP_REDIS_CONFIG', [
        'token' => '<your-license-token>',
        'host' => 'unix:///home/example/.system/redis.sock',
        'database' => 0, // change for each site
        'maxttl' => 86400 * 7,
        'timeout' => 1.0,
        'read_timeout' => 1.0,
        // 'prefetch' => true,
        // 'split_alloptions' => true,
        'debug' => false,
    ]);
     
    define('WP_REDIS_DISABLED', false);
  4. In the WordPress dashboard, find the widget «Object Cache Pro» and press «Enable Object Cache». If everything is in order, it should be highlighted «Status: Connected».
  5. Check the site is working.

Connection Redis by using Redis Object Cache and W3 Total Cache:

Content