Introduction#
When Redis uses Unix Sockets instead of TCP/IP, it can achieve about a 25% performance improvement.
Installation#
Using Ubuntu 16.04 LTS as an example,
- Install Redis
apt-get install redis-server
- Check which user Redis is currently running on
root@host:~# sudo ps aux grep redis
sudo: unable to resolve host www.xx.com
redis 29409 0.0 0.8 37224 8796 ? Ssl 10:43 0:00 /usr/bin/redis-server 127.0.0.1:6379
It can be seen that Redis is running on redis
- Add to the user group where
Apache
,Nginx
, andPHP-FPM
are located. Generally, software sources are installed underwww-data
, and compiled ones are underwww
, but this is not absolute. In my case, it is underwww-data
usermod -g www-data redis
- Create the folder where the unix socket is located
mkdir -p /var/run/redis/
- Assign permissions
chown -R redis:www-data /var/run/redis
- Modify the configuration file, mine is located at
/etc/redis/redis.conf
Remove the#
in front ofunixsocket
andunixsocketperm
, and change the value ofunixsocketperm
from700
to777
, otherwise the cache cannot be cleared
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /var/run/redis/redis.sock
unixsocketperm 777
- Restart
service redis-server restart
- If it is running normally, the
ls -lh
command will return the following result:
root@host:~# ls -lh /var/run/redis
total 4.0K
-rw-r--r-- 1 redis www-data 6 Mar 14 10:56 redis-server.pid
srwx------ 1 redis www-data 0 Mar 14 10:56 redis.sock
WP Settings#
-
Install the Redis Object Cache plugin
-
Add the following after
<?php
in thewp-config.php
file, the order must not be changed:
define('WP_REDIS_PATH', /var/run/redis/redis.sock
define('WP_REDIS_SCHEME', unix);
- Then the Redis Object Cache plugin will use Redis with Unix Sockets as the object cache instead of TCP/IP
Original article: Using Redis with Unix Sockets as an object cache in WP