How does WordPress use Redis to accelerate the cache plugin? CWP enables Redis cache

You may have heard of APC/APCu, Opcache, Xcache, they can speed up significantly WordPress or any kind of supported php script.

In this tutorial, I'll show you how to speed up WordPress with Redis Object Cache, and we'll go ahead and install Redis Cache on CWP, so let's get started.

What is a Redis cache?

  • Redis is the abbreviation of RE mote DI actionary Server.
  • Redis is a fast, open source in-memory key-value data structure store.
  • Redis comes with a common set of in-memory data structures that allow you to easily create a variety of custom applications.
  • Primary use cases for Redis include caching, session management, pub/sub, and leaderboards.
  • Redis is the most popular key-value store today.
  • Redis is BSD licensed, written in optimized C code, and supports multiple development languages.

How to enable Redis cache database in CWP control panel?

step 1:Go to CWP Control Panel

  • Select "PHP Settings" and then "PHP Version Switcher";
  • Then select "PHP Version" from the drop-down list, it is recommended to install the latest version of php 7 ▼
  • After the page reloads, you will see the PHP option available for installation (checkbox)

    How does WordPress use Redis to accelerate the cache plugin? CWP enables Redis cache

    Navigate to the bottom and find " redis " and select it and click " Build ” button, after the php rebuild process is complete, you can check if redis is running with the following command▼

    service redis status
    

    You will get output like this (inCentOS Tested on 7, CentOS 6 has different output like "running")

    [root@demo ~]# service redis status
    Redirecting to /bin/systemctl status redis.service
    ● redis.service - Redis persistent key-value database
    Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/redis.service.d
    └─limit.conf
    Active: active (running) since Sun 2022-02-20 16:41:24 +08; 12s ago
    Main PID: 2486 (redis-server)
    Status: "Ready to accept connections"
    CGroup: /system.slice/redis.service
    └─2486 /usr/bin/redis-server 127.0.0.1:6379

    Everything is fine at this point, now enter the following command to check if php redis is installed▼

    php -m | grep -i redis

    The output will be like this ▼

    [root@demo ~]# php -m | grep -i redis
    redis
    [root@demo ~]#

    If the output is redis , then all is well and we'll go ahead and install the WordPress and Redis integration.

    How to install CWP7 control panel, please see here ▼

    How to Enable Redis Cache Acceleration Plugin in WordPress?

    step 2:Before enabling the redis-object-cache plugin in WordPress, you must wp-config.php Add the following definitions to the file ▼

    define( 'WP_CACHE_KEY_SALT', 'www.chenweiliang.com:' );
    • will www.chenweiliang.com Replace with your website.

    If I have multiple Redis on one server, how do I configure them so that data is not mixed up?

    There are two ways.

    The first method is to configure different Redis DBs for different sites.

    Just add the following configuration to your wp-config.php file so that different sites can use different Redis databases.

    You can set different Redis databases incrementally starting from 0.

    define( 'WP_REDIS_DATABASE', 0 );

    The second way is that Redis cannot be controlled and the same database must be used.

    Then you can add different salts in it, so that even if you use the same database, the data will not be confused ▼

    define( 'WP_CACHE_KEY_SALT', 'www.chenweiliang.com:' );

    step 3:login to WordPress backend → Go to "Plugins" → "Install Plugins" ▼

    Log in to the WordPress backend → go to "Plugins" → "Install Plugin" You need to add this WordPress plugin: Redis Object cache Sheet 3

    step 4:assuming you have installed Redis Object cache plugin, now navigate to Redis settings and click "Enable Object Cache".

    After WordPress enables the Redis Cache Acceleration plugin, it will display "Connected" as shown below▼

    After WordPress enables the Redis Cache Acceleration plugin, it will show "Connected" Picture 4

    • congratulations!WordPress Redis Cache Acceleration Plugin successfully enabled!
    • You will notice that the load is now reduced and the site loads very fast.

    Special statement: If the program installed by default is in English, the screenshot is taken for grantedis in English.

    • However, some Chinese people say "the Chinese website uses English screenshots", "the arrows of the pictures are different"...
    • It can be seen that these Chinese people are completely restricted from free thinking.
    • Maybe because China is not an open and free country. If so, it seems that there is no freedom to speak and learn English in China at all?

    How to configure the Redis cache acceleration plugin?

    In general, it is enough to start directly, or we can further configure.

    Add the following configuration to our wp-config.php file▼

    define('WP_REDIS_CLIENT', 'pecl'); // 指定用于与 Redis 通信的客户端, pecl 即 The PHP Extension Community Library
    define('WP_REDIS_SCHEME', 'tcp'); // 指定用于与 Redis 实例进行通信的协议
    define('WP_REDIS_HOST', '127.0.0.1'); // Redis 服务器的 IP 或主机名
    define('WP_REDIS_PORT', '6379'); // Redis 端口
    define('WP_REDIS_DATABASE', '0'); // 接受用于使用该 SELECT 命令自动选择逻辑数据库的数值
    define('WP_CACHE_KEY_SALT', 'www.chenweiliang.com:'); // 设置所有缓存键的前缀( WordPress 多站点模式下使用)
    define('WP_REDIS_MAXTTL', '86400');

    How to check whether Redis cache is in effect?

    Use the following command to check whether the local Redis cache is generated ▼

    redis-cli monitor
    • Enter your website, refresh the page, and you can see that there is data output.

    Redis caching may also cause WordPress plugins and WordPress theme modifications to not take effect.

    Command to delete Redis cache manually

    redis-cli flushall

    #进入redis
    redis-cli
    
    #清空
    flushall
    
    #退出
    exit

    View the memory configuration of Redis ▼

    redis-cli info memory

    Back to query results ▼

    # Memory
    used_memory:24645472
    used_memory_human:23.50M
    used_memory_rss:40558592
    used_memory_rss_human:38.68M
    used_memory_peak:140777552
    used_memory_peak_human:134.26M
    used_memory_peak_perc:17.51%
    used_memory_overhead:1619888
    used_memory_startup:811872
    used_memory_dataset:23025584
    used_memory_dataset_perc:96.61%
    allocator_allocated:24964648
    allocator_active:26865664
    allocator_resident:37646336
    total_system_memory:17179869184
    total_system_memory_human:16.00G
    used_memory_lua:37888
    used_memory_lua_human:37.00K
    used_memory_scripts:0
    used_memory_scripts_human:0B
    number_of_cached_scripts:0
    maxmemory:0
    maxmemory_human:0B
    maxmemory_policy:noeviction
    allocator_frag_ratio:1.08
    allocator_frag_bytes:1901016
    allocator_rss_ratio:1.40
    allocator_rss_bytes:10780672
    rss_overhead_ratio:1.08
    rss_overhead_bytes:2912256
    mem_fragmentation_ratio:1.65
    mem_fragmentation_bytes:15954144
    mem_not_counted_for_evict:0
    mem_replication_backlog:0
    mem_clients_slaves:0
    mem_clients_normal:20496
    mem_aof_buffer:0
    mem_allocator:jemalloc-5.1.0
    active_defrag_running:0
    lazyfree_pending_objects:0
    lazyfreed_objects:0

    The following is how to configure the pid file after starting the Redis cache▼

    Solve the problem that the Redis server fails to start

    After restarting the VPS server, the Redis server may fail to obtain remote connection access.

    Troubleshoot Redis server startup failure: solve the problem of restarting and unable to obtain remote connection access

    To run the latest version of Redis with systemd, you need to edit the Redis configuration file:

    /etc/redis.conf

    Build and configure Redis with systemd support ▼

    daemonize no

    supervised auto
    • Try to restart the VPS server. If Redis can start as usual, it means that the Redis configuration file just edited works.

    Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does WordPress use Redis to accelerate the cache plugin? CWP Turn on Redis Cache" will help you.

    Welcome to share the link of this article:https://www.chenweiliang.com/cwl-26520.html

    Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

    🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
    📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
    Share and like if you like!
    Your sharing and likes are our continuous motivation!

     

    Comment

    Your email address will not be published. Required fields * Callout

    scroll to top