Redis installation on wordpress ubuntu & debian
sudo apt-get update && apt install redis-server
Redis configuration for wordpress
nano /etc/redis/redis.conf
Default binding port 6379 and 127.0.0.1
memory no limit
maxmemory limit
Cache eviction policy LRU
disable RDB persistent *
enabled thread IO (if persistent to disk enabled)
Max clients default = 10000
wordpress & redis install PHP client phpredis
sudo apt install php-redis
or incase php-fpm
sudo apt install php7.4-redis
its automatically added enabled as a extension.
you may edit php extension later.
wp – config php on each wordpress install
wp – object cache enable true
define(‘WP_CACHE’, true);
define(‘WP_CACHE_KEY_SALT’, ‘yoursite.com’);
in order to wordpress works with object cache you should add above lines in wp config php.
cache key salt used identify queries on redis cli monitor or anywhere later for debugging process.
you can check quickly in terminal
cat /var/www/html/raazkumar.com/wp-config.php our using grep command
root@-s-4vcpu-8gb-blr1-01:~# grep WP_CACHE_KEY_SALT /var/www/html/raazkumar.com/wp-config.php
//define(▒WP_CACHE_KEY_SALT▒, ▒raaz.com▒);
its commented
Install Redis Object Cache – WordPress plugin
Redis Object Cache By Till Krüss
Automatically enables You can monitor on wordpress dashboard like below
Redis slow query log should be below 100ms average 50ms. but my case its 160ms. without redis mysql average query execution time also 100ms.
but redis causing more delay than 100ms. what’s the problem. (when content updated.)
2nd image no updates like post add new, or edit.
Global Groups: [
“blog-details”,
“blog-id-cache”,
“blog-lookup”,
“global-posts”,
“networks”,
“rss”,
“sites”,
“site-details”,
“site-lookup”,
“site-options”,
“site-transient”,
“users”,
“useremail”,
“userlogins”,
“usermeta”,
“user_meta”,
“userslugs”,
“redis-cache”,
“blog_meta”
]
Ignored Groups: [
“counts”,
“plugins”,
“themes”
]
Redis object cache with W3tc (wp rocket won’t support now)
after installing redis, added wp config php.
then go to w3tc general settings and enable redis cache.
Using persistent connection doesn’t initialize redis driver on each request
Redis vs memcached which is best for wordpress
Memcached only supports key value, but redis support multiple data structures and replication etc.
redis is also termed as memcached on steroids check redis vs memcached
Cloudways redis wordpress managed no more dig
cloudways did a excellent jobs by managing cloud server, you don’t need to worry about server related problems like redis slow performance.
you can just start with them by 20$ per month. checkout my cloudways review pricing.
Monitoring redis wordpress with commands slow query
open termial and type
redis-cli
then slowlog get 10
1) (integer) 6
2) (integer) 1619161803
3) (integer) 10892 // microseconds 108 ms (ideal 50ms)
4) 1) “SET”
2) “2xpwp:posts:33996”
3) “O:8:\”stdClass\”:24:{s:2:\”ID\”;i:33996;s:11:\”post_author\”;s:1:\”1\”;s:9:\”post_date\”;s:19:\”2021-02-26 05:09:00\”;s:13:\”post_date_gmt\”;s… (4817 more bytes)”
4) “nx”
5) “127.0.0.1:17078”
6) “”
3) 1) (integer) 5
2) (integer) 1619161384
3) (integer) 17912 // 170ms
4) 1) “GET”
2) “xpwp:posts:42871”
5) “127.0.0.1:16418”
6) “”
Performance tips
persistent connections. (Using persistent connections to Redis means that the connection is not closed until the PHP process dies)
phpredis or predis test it for redis libraries.
find out latency in case of remote cluster (redis latency monitor disabled by default)
redis-cli –latency -p 6379 -h 127.0.0.1
root@-s-4vcpu-8gb-blr1-01:~# redis-cli –latency -p 6379 -h 127.0.0.1
min: 0, max: 12, avg: 0.31 (1382 samples)
Disable RDB persistence
Redis was saving data to disk every few minutes: