安裝後記檢查 PhpRedis 沒有有啟用,如果沒有的話再補上 php-redis
購物站點了可以秒反應,非常有感 XD
啟用後記得檢查設定檔
/wp-admin/options-general.php?page=redis-cache#diagnostics
Status: Connected
Client: PhpRedis (v6.1.0)
Drop-in: Valid
Disabled: No
Ping: 1
Errors: []
PhpRedis: 6.1.0
Relay: Not loaded
Predis: 2.1.2
Credis: Not loaded
PHP Version: 7.4.33
Plugin Version: 2.5.4
Redis Version: 7.4.2
Multisite: No
Metrics: Enabled
Metrics recorded: 427
Filesystem: Writable
Global Prefix: "wp_"
Blog Prefix: "wp_"
Timeout: 1
Read Timeout: 1
Retry Interval:
WP_REDIS_PLUGIN_PATH: "/var/www/wp/test1/wp-content/plugins/redis-cache"
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"
]
Unflushable Groups: []
Groups Types: {
"blog-details": "global",
"blog-id-cache": "global",
"blog-lookup": "global",
"global-posts": "global",
"networks": "global",
"rss": "global",
"sites": "global",
"site-details": "global",
"site-lookup": "global",
"site-options": "global",
"site-transient": "global",
"users": "global",
"useremail": "global",
"userlogins": "global",
"usermeta": "global",
"user_meta": "global",
"userslugs": "global",
"redis-cache": "global",
"blog_meta": "global",
"counts": "ignored",
"plugins": "ignored",
"themes": "ignored"
}
Drop-ins: [
"advanced-cache.php v by ",
"Redis Object Cache Drop-In v2.5.4 by Till Krüss"
]
如果你的有多個站,建議用Docker把快取資料庫分開,才不會混亂
Docker的範例
version: '3'
services:
redis-site1:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6381:6379"
volumes:
- redis-data-site1:/data
redis-site2:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6382:6379"
volumes:
- redis-data-site2:/data
redis-site3:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6383:6379"
volumes:
- redis-data-site3:/data
redis-site4:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6384:6379"
volumes:
- redis-data-site4:/data
redis-site5:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6385:6379"
volumes:
- redis-data-site5:/data
redis-site6:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6386:6379"
volumes:
- redis-data-site6:/data
redis-site7:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6387:6379"
volumes:
- redis-data-site7:/data
redis-site8:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6388:6379"
volumes:
- redis-data-site8:/data
redis-site9:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6389:6379"
volumes:
- redis-data-site9:/data
redis-site10:
image: redis:latest
command: redis-server --port 6379 --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes
ports:
- "6390:6379"
volumes:
- redis-data-site10:/data
volumes:
redis-data-site1:
redis-data-site2:
redis-data-site3:
redis-data-site4:
redis-data-site5:
redis-data-site6:
redis-data-site7:
redis-data-site8:
redis-data-site9:
redis-data-site10:
設定時對應好 port 就行了
define('WP_REDIS_HOST', 'localhost'); // 或你的 Redis 伺服器 IP
define('WP_REDIS_PORT', 6381);
define('WP_REDIS_TIMEOUT', 1);
define('WP_REDIS_READ_TIMEOUT', 1);
define('WP_REDIS_SCHEME', 'tcp');
define('WP_REDIS_CLIENT', 'phpredis');