2.14.1.2.5. Configure Redis in WordPress

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

  1. Open the site admin panel.
  2. Install and activate the Redis Object Cache plugin.
  3. Edit the site configuration file, wp-config.php, and add the following lines at the beginning, right after <?php (in the second line, replace example with the name of the hosting account where the site is hosted; in the third line, replace example with 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');
  4. In the site admin panel, go to the "Settings → Redis" section and click "Enable object cache":If everything is working properly, "Connected" should appear in the "Status" field at the top of the section:
  5. Check the site operation.
  1. Open the site admin panel.
  2. Install and activate the W3 Total Cache plugin.
  3. Go to the "Performance → General Settings" section:
  4. In the "Object Cache" section:
    1. In the "Object Cache" line, select "Enabled".
    2. In the "Object Cache Method" line, select "Redis".
    3. Save the changes.
  5. Go to the "Performance → Object Cache" section:
  6. In the "Advanced" block:
    1. In the "Redis hostname:port / IP:port" field, specify /home/example/.system/redis.sock (replace example with the name of the hosting account where the site is hosted) and click "Test":If everything is okay, the green text "Test passed" should appear:
    2. Save the changes.
  7. Follow the same steps for "Page Cache" and "Database Cache".
  8. Check the site operation.

The plugin is paid

You can purchase a license on the official site.
  1. Open the site admin panel.
  2. Install and activate the Object Cache Pro plugin (you can do this either by uploading the plugin archive via the WordPress dashboard or by manually placing the plugin directory in the WordPress plugins directory).
  3. Place the plugin directory in the WordPress plugins directory.
  4. Edit the site configuration file wp-config.php and add the following lines to it (in the second line, replace <your-license-token> with your license token; in the third line, replace example with the name of the hosting account where 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);
  5. In the WordPress dashboard, find the "Object Cache Pro" widget and click "Enable Object Cache". If everything is working properly, "Status: Connected" should appear.
  6. Check the site operation.

Connecting Redis using Redis Object Cache and W3 Total Cache:

Content

    (1)