Redis Cache By Xon

Redis Cache By Xon 2.8.0

No permission to download

Nirjonadda

Well-known member
You need to have the $config['cache']['context']['page']['config'] set; or it'll just use defaults and does not fall back on the global config.

PHP:
$config['cache']['context']['css'] = [
            'namespace' => 'sv',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
'server' => '127.0.0.1',
'port' => 6380,
            ],
        ];
This will store CSS to a seperate redis instance on port 6380. There is only any point to adding the $config['cache']['context'] if they talk to a different backend

Does now correct this code?

Code:
// START Redis configuration //
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'xfredis_';

$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 6,
'read_timeout' => 1,
'timeout' => 1,
'serializer' => 'igbinary',
//        'serializer' => 'php',
'persistent' => true,
);
// END Redis configuration //

// START Guest page caching //
$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
// END Guest page caching //

// START CSS caching //
$config['cache']['context']['css'] = [
            'namespace' => 'sv',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
'server' => '127.0.0.1',
'port' => 6380,
            ],
        ];
// END CSS caching //
 

Nirjonadda

Well-known member
This will store CSS to a seperate redis instance on port 6380.
Port 6380 not work, only work port 6379

Code:
CredisException: Template public:PAGE_CONTAINER error: Connection to Redis 127.0.0.1:6380 failed after 2 failures.Last Error : (1) Connection refused src/addons/SV/RedisCache/Credis/Client.php:476
 

duderuud

Well-known member
You need an extra Redis instance to make that work. See here for some more info.

Just tested the css caching and it seems to work. Too bad the extra Redis info in the admin page doesn't show the 2nd instance.
 

Tealk

Well-known member
You need an extra Redis instance to make that work. See here for some more info.
You could also use different databases in the Redis instance:
Code:
$config['cache']['config'] = array(
        'server' => '127.0.0.1',
        'port' => 6379,
        'password' => 'xxx',
        'database' => 0, <-- Here you have to count up
        );
 

Xon

Well-known member
There really isn't any point to setting up a second cache connector unless it is talking to a separate backend.

Just tested the css caching and it seems to work. Too bad the extra Redis info in the admin page doesn't show the 2nd instance.
Yeah, need to hook that up :(
 

maxicep

Active member
Does now correct this code?

Code:
// START Redis configuration //
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'xfredis_';

$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 6,
'read_timeout' => 1,
'timeout' => 1,
'serializer' => 'igbinary',
//        'serializer' => 'php',
'persistent' => true,
);
// END Redis configuration //

// START Guest page caching //
$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
// END Guest page caching //

// START CSS caching //
$config['cache']['context']['css'] = [
            'namespace' => 'sv',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
'server' => '127.0.0.1',
'port' => 6380,
            ],
        ];
// END CSS caching //
Remove that multiple line
$config['cache']['enabled'] = true;
 

Nirjonadda

Well-known member
@Xon User logout will be show Security error occurred. Please press back, refresh the page, and try again with Guest page caching. Please can you let me know that how to fixing this issue? I am using phpredis 5.1.1 with Redis Version 3.2.12

ScreenShot01281.png

Issue happened with this code:

Code:
// START Guest page caching //
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
// END Guest page caching //
Full Redis Cache code with Mobile detection:

Code:
// START Redis configuration //
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'xfredis_';

$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 6,
'read_timeout' => 1,
'timeout' => 1,
'serializer' => 'igbinary',
//        'serializer' => 'php',
'persistent' => true,
);
// END Redis configuration //

// START Guest page caching //
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
// END Guest page caching //

// START CSS caching //
$config['cache']['context']['css'] = [
            'namespace' => 'sv',
            'provider' => 'SV\RedisCache\Redis',
            'config' => [
'server' => '127.0.0.1',
'port' => 6379,
            ],
        ];
// END CSS caching //

// START Mobile detection with full page caching //
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};
// END Mobile detection with full page caching //
 

Xon

Well-known member
Please change this line;
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
to
PHP:
$config['cache']['context']['page']['config'] = [
        'server' => '127.0.0.1',
        'port' => 6379,
    ];
It probably shouldn't hurt, but just to keep the config sane.

I haven't seen this sort of error before with page caching and haven't heavily tested page caching before.
 

Nirjonadda

Well-known member
Please change this line;
$config['cache']['context']['page']['config'] = ['127.0.0.1'];
to
PHP:
$config['cache']['context']['page']['config'] = [
        'server' => '127.0.0.1',
        'port' => 6379,
    ];
It probably shouldn't hurt, but just to keep the config sane.

I haven't seen this sort of error before with page caching and haven't heavily tested page caching before.
Does not work. Still issue User logout will be show Security error occurred. Please press back, refresh the page, and try again. User will be logged out but this popup showing and does not Redirects to logout.
 

Xon

Well-known member
I believe this error likely will happen even with the stock Redis connection. Can you try swapping the lines;
Code:
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = [
        'server' => '127.0.0.1',
        'port' => 6379,
    ];
to
Code:
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379,
    ];
This will use the built-in redis adapter. It should work, but I believe it'll still trigger the same error
 

Nirjonadda

Well-known member
I believe this error likely will happen even with the stock Redis connection. Can you try swapping the lines;
Code:
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = [
        'server' => '127.0.0.1',
        'port' => 6379,
    ];
to
Code:
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379,
    ];
This will use the built-in redis adapter. It should work, but I believe it'll still trigger the same error
Checked with both code but User logout will be show Security error occurred. Please press back, refresh the page, and try again. User will be logged out but this popup showing and does not Redirects to logout.

@Nirjonadda , I get the same error, but I don't think it has anything to do with this add-on.
So this xenforo bug because this error happened with provider Redis.
 
  • Like
Reactions: Xon

Eagle

Well-known member
Redis have not come back automatically after a server reboot. So each time I reboot the server my site are not working because of Redis. It won't keep running until manually run redis-server. I found a solution but does not solve my problem. Is there any solution available?
 

Xon

Well-known member
Only very limited server support can be offered for free, especially for something with so few details

But on a modern linux platform with systemd, all you need todo is run systemctl enable redis to configure redis to start at boot
 

duderuud

Well-known member
Looks like this add-on needs to be updated for PHP 7.4:

Code:
ErrorException: Template error: implode(): Passing glue string after array is deprecated. Swap the parameters
src/addons/SV/RedisCache/Credis/Client.php:1435
Stack trace

#0 [internal function]: XF\Template\Templater->handleTemplateError()
#1 src/addons/SV/RedisCache/Credis/Client.php(1435): implode()
#2 src/addons/SV/RedisCache/Credis/Client.php(1015): Credis_Client::_prepare_command()
#3 src/addons/SV/RedisCache/Redis.php(236): Credis_Client->__call()
#4 src/addons/SV/RedisCache/CacheProvider.php(46): SV\RedisCache\Redis->doFetch()
#5 src/addons/SV/RedisCache/XF/CssRenderer.php(179): SV\RedisCache\CacheProvider->fetch()
#6 src/XF/Template/Templater.php(2978): SV\RedisCache\XF\CssRenderer->parseLessColorValue()
#7 [internal function]: XF\Template\Templater->fnParseLessColor()
#8 src/XF/Template/Templater.php(941): call_user_func_array()
#9 internal_data/code_cache/templates/l2/s8/public/PAGE_CONTAINER.php(2680): XF\Template\Templater->func()
#10 src/XF/Template/Templater.php(1320): XF\Template\Templater->{closure}()
#11 src/XF/Pub/App.php(544): XF\Template\Templater->renderTemplate()
#12 src/XF/App.php(1995): XF\Pub\App->renderPageHtml()
#13 src/XF/Mvc/Dispatcher.php(402): XF\App->renderPage()
#14 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render()
#15 src/XF/App.php(2184): XF\Mvc\Dispatcher->run()
#16 src/XF.php(391): XF\App->run()
#17 index.php(20): XF::runApp()
#18 {main}


Request state

array(4) {
["url"] => string(18) "/service-worker.js"
["referrer"] => bool(false)
["_GET"] => array(1) {
["/service-worker_js"] => string(0) ""
}
["_POST"] => array(0) {
}
}
 

dethfire

Well-known member
My homepage is displaying the sql array at the top. I need to disabled until fixed. Actually this is from the optimized list update.
 
Top