Redis Cache By Xon

Redis Cache By Xon 2.17.2

No permission to download
Hi,

I just move to a new server. I get the bellow Apache error. I am running Ubuntu 20.04 with a Plesk deployment (last version).
I don't understand fro the log, what the actual problem is. Would be happy if someone can help me to solve the issue.

My XenForo Redis Config:
Bash:
#redis cache
$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
];

Here are the Redis settings on Plesk Docker container.

View attachment 286382
XenForo Error Log.

View attachment 286383


Bash:
2023-05-24 16:22:48    Error    XXX.XXX.XXX.XXX        AH01071: Got error 'PHP message: PHP Fatal error: Uncaught RedisException: READONLY You can't write against a read only replica. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1280\nStack trace:\n#0 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php(1280): Redis->set('xf_data_codeEve...', 'gz:\\x1F\\x8Bx\\x01\\xBD[\\xDDr\\x9B\\xC8\\x12~...', 3600)\n#1 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(598): Credis_Client->__call('set', Array)\n#2 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(49): SV\\RedisCache\\Redis->SV\\RedisCache\\{closure}()\n#3 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(606): SV\\RedisCache\\Redis->redisQueryForStat('sets', Object(Closure))\n#4 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/CacheProvider.php(92): SV\\RedisCache\\Redis->doSave('xf_data_codeEve...', Array, 3600)\n#5 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(18...', referer: https://www.google.com/                Apache error
2023-05-24 16:22:48    Error    XXX.XXX.XXX.XXX        AH01071: Got error 'PHP message: PHP Fatal error: Uncaught RedisException: READONLY You can't write against a read only replica. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1280\nStack trace:\n#0 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php(1280): Redis->set('xf_data_codeEve...', 'gz:\\x1F\\x8Bx\\x01\\xBD[\\xDDr\\x9B\\xC8\\x12~...', 3600)\n#1 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(598): Credis_Client->__call('set', Array)\n#2 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(49): SV\\RedisCache\\Redis->SV\\RedisCache\\{closure}()\n#3 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(606): SV\\RedisCache\\Redis->redisQueryForStat('sets', Object(Closure))\n#4 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/CacheProvider.php(92): SV\\RedisCache\\Redis->doSave('xf_data_codeEve...', Array, 3600)\n#5 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(18...', referer: https://www.MYDOMAIN.com/                Apache error
2023-05-24 16:22:48    Error    XXX.XXX.XXX.XXX        AH01071: Got error 'PHP message: PHP Fatal error: Uncaught RedisException: READONLY You can't write against a read only replica. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1280\nStack trace:\n#0 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php(1280): Redis->set('xf_data_codeEve...', 'gz:\\x1F\\x8Bx\\x01\\xBD[\\xDDr\\x9B\\xC8\\x12~...', 3600)\n#1 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(598): Credis_Client->__call('set', Array)\n#2 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(49): SV\\RedisCache\\Redis->SV\\RedisCache\\{closure}()\n#3 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(606): SV\\RedisCache\\Redis->redisQueryForStat('sets', Object(Closure))\n#4 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/CacheProvider.php(92): SV\\RedisCache\\Redis->doSave('xf_data_codeEve...', Array, 3600)\n#5 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(18...', referer: https://www.MYDOMAIN.com/whats-new/posts/833809/                Apache error
2023-05-24 16:22:48    Error    XXX.XXX.XXX.XXX        AH01071: Got error 'PHP message: PHP Fatal error: Uncaught RedisException: READONLY You can't write against a read only replica. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1280\nStack trace:\n#0 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php(1280): Redis->set('xf_data_codeEve...', 'gz:\\x1F\\x8Bx\\x01\\xBD[\\xDDr\\x9B\\xC8\\x12~...', 3600)\n#1 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(598): Credis_Client->__call('set', Array)\n#2 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(49): SV\\RedisCache\\Redis->SV\\RedisCache\\{closure}()\n#3 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(606): SV\\RedisCache\\Redis->redisQueryForStat('sets', Object(Closure))\n#4 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/CacheProvider.php(92): SV\\RedisCache\\Redis->doSave('xf_data_codeEve...', Array, 3600)\n#5 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(18...'

This is the error you need to resolve:
Code:
RedisException: READONLY You can't write against a read only replica

Remove that last line in the configuration that looks to be a truncated REDIS_REPLICA_READ_ONLY You will likely need to blow away that redis instance and build a new one to remove this broke state.
 
This is the error you need to resolve:
Code:
RedisException: READONLY You can't write against a read only replica

Remove that last line in the configuration that looks to be a truncated REDIS_REPLICA_READ_ONLY You will likely need to blow away that redis instance and build a new one to remove this broke state.

REDIS_REPLICA_READ_ONLY > no

I just added that recently, with the hope of being to solve the issue.

I had the issue before I added it, I have to say, however, that it doesn't matter :(

After about 6-8 hours I get a 500 error and the forum is no longer reachable. If I restart the redis container, site works again for another 6-8 hours.
It's realy strange.

WHAT CAUSE MIGHT ALSO HAVE ?
 
This is very much a sysadmin task that you should post about in the Server configuration and hosting sub-forum. I don't have experience in using redis in a docker container on plex.

You would need to post the actual XF error (instead of just error 500), and likely get the redis logs to determine what is failing.
 
This is very much a sysadmin task that you should post about in the Server configuration and hosting sub-forum. I don't have experience in using redis in a docker container on plex.

You would need to post the actual XF error (instead of just error 500), and likely get the redis logs to determine what is failing.

There two XF Error

1685004312585.png

1685004378927.png

1685004421505.png
 

Attachments

  • 1685004230936.webp
    1685004230936.webp
    123.1 KB · Views: 3
If it is abruptly failing, this implies something has been reconfigured.

You must make sure your redis instance it not accessible to wider internet or people can do whatever they want to it.

But server specific configuration is beyond the support I offer for this free add-on.
 
If it is abruptly failing, this implies something has been reconfigured.

You must make sure your redis instance it not accessible to wider internet or people can do whatever they want to it.

But server specific configuration is beyond the support I offer for this free add-on.

Username and Password doesn't work.

I have activate now username and password to prevent access, redis container does start without issues:

1685013558248.png


Code:
1:C 25 May 2023 11:14:36.974 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 25 May 2023 11:14:36.974 # Redis version=7.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 25 May 2023 11:14:36.974 # Configuration loaded
1:M 25 May 2023 11:14:36.975 * monotonic clock: POSIX clock_gettime
1:M 25 May 2023 11:14:36.975 * Running mode=standalone, port=6379.
1:M 25 May 2023 11:14:36.975 # Server initialized
1:M 25 May 2023 11:14:36.981 * Creating AOF base file appendonly.aof.1.base.rdb on server start
1:M 25 May 2023 11:14:36.991 * Creating AOF incr file appendonly.aof.1.incr.aof on server start
1:M 25 May 2023 11:14:36.991 * Ready to accept connections
[38;5;6mredis [38;5;5m11:14:36.90 [0m
[38;5;6mredis [38;5;5m11:14:36.90 [0m[1mWelcome to the Bitnami redis container[0m
[38;5;6mredis [38;5;5m11:14:36.90 [0mSubscribe to project updates by watching [1mhttps://github.com/bitnami/containers[0m
[38;5;6mredis [38;5;5m11:14:36.91 [0mSubmit issues and feature requests at [1mhttps://github.com/bitnami/containers/issues[0m
[38;5;6mredis [38;5;5m11:14:36.91 [0m
[38;5;6mredis [38;5;5m11:14:36.91 [0m[38;5;2mINFO [0m ==> ** Starting Redis setup **
[38;5;6mredis [38;5;5m11:14:36.92 [0m[38;5;2mINFO [0m ==> Initializing Redis
[38;5;6mredis [38;5;5m11:14:36.93 [0m[38;5;2mINFO [0m ==> Setting Redis config file
[38;5;6mredis [38;5;5m11:14:36.95 [0m[38;5;2mINFO [0m ==> ** Redis setup finished! **
[38;5;6mredis [38;5;5m11:14:36.96 [0m[38;5;2mINFO [0m ==> ** Starting Redis **

That my XF config:

1685013677038.png

I the strange thing is, if start redis with
ALLOW_EMPTY_PASSWORD=yes

and comment out authentification (username and password) in the config it does work without issues.
Is my config correct so far ?

Edit:
Apache give me following error:
Code:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught CredisException: NOAUTH Authentication required. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1350\nStack trace:\n#0 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(467): Credis_Client->__call('mget', Array)\n#1 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(49): SV\\RedisCache\\Redis->SV\\RedisCache\\{closure}()\n#2 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Redis.php(498): SV\\RedisCache\\Redis->redisQueryForStat('gets', Object(Closure))\n#3 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/CacheProvider.php(63): SV\\RedisCache\\Redis->doFetchMultiple(Array)\n#4 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(115): SV\\RedisCache\\CacheProvider->fetchMultiple(Array)\n#5 /var/www/vhosts/MYDOMAIN.com/httpdocs/src/XF/DataRegistry.php(83): XF\\DataRegistry->readFromCache(Array, Array)\n#6 /var/www/vhosts/MYDOMAIN.com/httpdocs/sr...''

Why I get this Error:
Code:
Uncaught CredisException: NOAUTH Authentication required. in /var/www/vhosts/MYDOMAIN.com/httpdocs/src/addons/SV/RedisCache/Credis/Client.php:1350
 
Last edited:
The username/password you are setting in config.php is being ignored when the host/port is being set.

It needs to be this;
PHP:
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
'username' => 'rdsadm',
'password' => 'mypass',
];
 
The username/password you are setting in config.php is being ignored when the host/port is being set.

It needs to be this;
PHP:
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
'username' => 'rdsadm',
'password' => 'mypass',
];

Thanks for your reply mate. I just notice that I get error 500 only if I enable:

$config['cache']['enabled'] = true;

Would this mean that Redis won't cache the data when it's disabled?

If so, how could I fix that problem?
 
Thanks for your reply mate. I just notice that I get error 500 only if I enable:

$config['cache']['enabled'] = true;

Would this mean that Redis won't cache the data when it's disabled?
Correct, without that line the caching isn't doing anything.

If so, how could I fix that problem?
Without seeing the php error which is triggering the http 500 to be returned; no idea!
 
This addon doesn't add caching that would touch the ads. It only caches some thread list totals based on the query arguments and user's permission combination id.
 
@Xon Okay I've installed redis on my dedicated Ubuntu 20.04 LTS server, and confirmed that is now running. I'm also about it install your mod. But then what's next? I'm seeing a lot of different chatter regarding setup, etc. Esp. security. Please clarify. Thanks!!
 
The minimum configuration (server/port, and enable session) is perfectly fine for virtually all installs.
 
The minimum configuration (server/port, and enable session) is perfectly fine for virtually all installs.
Okay, I did this in my config.php

$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;

$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => 6379,
];

I get no errors, and my forum does seem more responsive!
 
  • Like
Reactions: Xon
You need the provider, this is the configuration you want:
PHP:
$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
    'server' => '127.0.0.1',
    'port' => 6379,
];
 
I'm using Centmin mod, and installed this addon, then used the instructions near the bottom here https://community.centminmod.com/th...mod-123-09beta01-lemp-stack.16060/#post-70603 (search "Xon's Redis Cache Addon") to edit src/config.php.

This is what I changed it to:
Code:
// Default cache settings
// $config['cache']['enabled'] = true;
// $config['cache']['provider'] = 'Memcached';
// $config['cache']['config'] = [
//     'server' => '127.0.0.1',
//     'port' => '11211'
// ];


// Xon RedisCache settings
// global cache
$config['cache']['enabled'] = true;
$config['cache']['namespace'] = 'xfaredis';
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6379,
    'database' => 2,
    'compress_data' => 6,
    'serializer' => 'igbinary',
    'use_lua' => true,
//  'read_timeout' => 1,
//  'timeout' => 1,
//  'lifetimelimit' => 2592000,
//  'compress_threshold' => 20480,
//  'persistent' => true
];

// session cache
$config['cache']['sessions'] = true;

// guest page cache
$config['pageCache']['enabled'] = true;
//$config['pageCache']['enabled'] = false;
$config['pageCache']['lifetime'] = 900;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['namespace'] = 'xfaredispagecache_';
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
   'host' => '127.0.0.1',
   'port' => 6480,
   'serializer' => 'igbinary',
   'database' => 4,
// 'timeout' => 1,
// 'persistent' => true
];

Now my /admin.php only shows a big red error (and my forum doesn't load):
Code:
CredisException: Connection to Redis tcp://127.0.0.1:6480 failed after 2 failures.Last Error : (1) Connection refused in src/addons/SV/RedisCache/Credis/Client.php at line 598

    Credis_Client->connect() in src/addons/SV/RedisCache/Credis/Client.php at line 594
    Credis_Client->connect() in src/addons/SV/RedisCache/Credis/Client.php at line 944
    Credis_Client->__call() in src/addons/SV/RedisCache/Credis/Client.php at line 772
    Credis_Client->select() in src/addons/SV/RedisCache/Cm_Cache_Backend_Redis.php at line 414
    SV\RedisCache\Cm_Cache_Backend_Redis->_applyClientOptions() in src/addons/SV/RedisCache/Cm_Cache_Backend_Redis.php at line 264
    SV\RedisCache\Cm_Cache_Backend_Redis->__construct() in src/addons/SV/RedisCache/Redis.php at line 204
    SV\RedisCache\Redis->__construct() in src/XF/CacheFactory.php at line 68
    XF\CacheFactory->instantiate() in src/XF/CacheFactory.php at line 36
    XF\CacheFactory->create() in src/XF/App.php at line 709
    XF\App->XF\{closure}() in src/XF/Container.php at line 234
    XF\Container->create() in src/XF/App.php at line 2658
    XF\App->cache() in src/addons/SV/RedisCache/Repository/Redis.php at line 56
    SV\RedisCache\Repository\Redis->insertRedisInfoParams() in src/addons/SV/RedisCache/XF/Admin/Controller/Index.php at line 16
    SV\RedisCache\XF\Admin\Controller\Index->actionIndex() in src/addons/SV/SearchImprovements/XF/Admin/Controller/Index.php at line 19
    SV\SearchImprovements\XF\Admin\Controller\Index->actionIndex() in src/XF/Mvc/Dispatcher.php at line 352
    XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 259
    XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
    XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
    XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2487
    XF\App->run() in src/XF.php at line 524
    XF::runApp() in admin.php at line 13

I tried this command per instructions elsewhere in this thread:
Code:
redis-cli flushall
OK

I rebooted my server and it's still down.

I have the admin panel password protected via /usr/local/nginx/conf/htpasswd so I thought it might be a password issue, but when I added
Code:
$config['cache']['config']['username'] = 'myUsername'; // requires redis 6+, or for cloud redis installations
$config['cache']['config']['password'] = 'mypw';
That made it worse. Now I get only a blank white page everywhere. Whereas before, I could access other parts of the ACP.

I removed the PW and noticed that it was failing on port 6480, which I noticed as part of this extra stuff that @eva2000 added. So I removed it, and now it works:
Code:
// session cache
$config['cache']['sessions'] = true;

// guest page cache
$config['pageCache']['enabled'] = true;
//$config['pageCache']['enabled'] = false;
$config['pageCache']['lifetime'] = 900;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['namespace'] = 'xfaredispagecache_';
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
   'host' => '127.0.0.1',
   'port' => 6480,
   'serializer' => 'igbinary',
   'database' => 4,
// 'timeout' => 1,
// 'persistent' => true
];

@eva2000 I can't comment on your post, but could you clarify the Xon's Redis Cache Addon For Xenforo 2.x section so that noobs like me can just copy-paste the standard settings? And if you break each part up into its own comment that makes it easier to reference specific parts (IE Xon's Redis Cache Addon For Xenforo 2.x in its own comment instead of at the bottom of a very large comment).

And @Xon it would be helpful if you added some basic installation instructions (I didn't see any except a link to eva's post), such as:
Edit src/config.php:
Remove:
// Default cache settings
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
'server' => '127.0.0.1',
'port' => '11211'
];

And for Centmin mod, replace with:
// global cache
$config['cache']['enabled'] = true;
$config['cache']['namespace'] = 'xfaredis';
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 2,
'compress_data' => 6,
'serializer' => 'igbinary',
'use_lua' => true,
// 'read_timeout' => 1,
// 'timeout' => 1,
// 'lifetimelimit' => 2592000,
// 'compress_threshold' => 20480,
// 'persistent' => true
];

I don't even know if that's correct still. I know you give a sample in README.md but it doesn't even say what file (src/config.php) to edit.
 
Last edited:
Top Bottom