How to use redis as mediawiki cache backends: Difference between revisions

From 清冽之泉
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
grep -r apc /etc/php/8.2/
grep -r apc /etc/php/8.2/
sudo emacs /etc/php/8.2/mods-available/apcu.ini # 注释掉对 apcu 的调用
sudo emacs /etc/php/8.2/mods-available/apcu.ini # 注释掉对 apcu 的调用
# 进 LocalSettings.php 取消对 CACHE_ACCEL 的调用
## Shared memory settings
## $wgMainCacheType = CACHE_ACCEL;
## $wgMemCachedServers = [];
</syntaxhighlight>
</syntaxhighlight>



Revision as of 17:18, 14 May 2025

# 如果已经使用过 apcu 作为缓存,要先去除 apcu 缓存
grep -r apc /etc/php/8.2/
sudo emacs /etc/php/8.2/mods-available/apcu.ini # 注释掉对 apcu 的调用

# 进 LocalSettings.php 取消对 CACHE_ACCEL 的调用
## Shared memory settings
## $wgMainCacheType = CACHE_ACCEL;
## $wgMemCachedServers = [];
# 安装并配置 redis 作缓存后端
sudo apt install redis-server php-redis

# 编辑 LocalSettings.php
$wgObjectCaches['redis'] = [
    'class'                => 'RedisBagOStuff',
    'servers'              => [ '127.0.0.1:6379' ],
    // 'connectTimeout'    => 1,
    // 'persistent'        => false,
    // 'password'          => 'secret',
    // 'automaticFailOver' => true,
];

$wgMainCacheType    = 'redis';
$wgParserCacheType  = 'redis';        // 可选
$wgMessageCacheType = 'redis';        // 可选
// 若使用新版 API,可直接写 'redis'
// $wgMainCacheType = 'redis';
## $smwgMainCacheType  = CACHE_REDIS;

$wgJobTypeConf['default'] = [
    'class'          => 'JobQueueRedis',
    'redisServer'    => '127.0.0.1:6379',
    'redisConfig'    => [],
    'daemonized'     => true
 ];