Redis Cache By Xon

Redis Cache By Xon 2.18.1

No permission to download
This add-on is compatible with XF2.3. It was a little dodgy if you use the web-upgrader but I think that was fixed with before 2.3.0 on XF's side
 
@Xon Server error log on XF 2.3.0

Code:
Less_Exception_Compiler: parse_less_func(@someVar: unit(lightness(hsl(var(--xf-contentBg)))); #test { color: @someVar; }) render error: error evaluating function `unit` The first argument to unit must be a number. index: 10 src/vendor/oyejorge/less.php/lib/Less/Tree/Call.php:80

Generated by: Unknown account Jul 6, 2024 at 10:51 PM

Stack trace

#0 src/vendor/oyejorge/less.php/lib/Less/Tree/Expression.php(46): Less_Tree_Call->compile(Object(Less_Environment))
#1 src/vendor/oyejorge/less.php/lib/Less/Tree/Value.php(25): Less_Tree_Expression->compile(Object(Less_Environment))
#2 src/vendor/oyejorge/less.php/lib/Less/Tree/Rule.php(76): Less_Tree_Value->compile(Object(Less_Environment))
#3 src/vendor/oyejorge/less.php/lib/Less/Tree/Ruleset.php(95): Less_Tree_Rule->compile(Object(Less_Environment))
#4 src/vendor/oyejorge/less.php/lib/Less/Parser.php(181): Less_Tree_Ruleset->compile(Object(Less_Environment))
#5 src/addons/SV/StandardLib/XF/CssRenderer.php(29): Less_Parser->getCss()
#6 src/addons/SV/RedisCache/XF/CssRenderer.php(216): SV\StandardLib\XF\CssRenderer->parseLessColorFuncValue('@someVar: unit(...', false)
#7 src/addons/SV/StandardLib/TemplaterHelper.php(527): SV\RedisCache\XF\CssRenderer->parseLessColorFuncValue('unit(lightness(...', false)
#8 src/XF/Template/Templater.php(1220): SV\StandardLib\TemplaterHelper->fnParseLessFunc(Object(SV\LazyImageLoader\XF\Template\Templater), false, 'unit(lightness(...')
#9 internal_data/code_cache/templates/l1/s2/public/sv_bbcode_modinterrupt_svg.css.php(16): XF\Template\Templater->func('parse_less_func', Array, false)
#10 src/XF/Template/Templater.php(1792): XF\Template\Templater->{closure}(Object(SV\LazyImageLoader\XF\Template\Templater), Array, NULL)
#11 src/XF/Template/Templater.php(1866): XF\Template\Templater->renderTemplate('sv_bbcode_modin...', Array)
#12 internal_data/code_cache/templates/l1/s2/public/sv_bbcode_modinterrupt_alert.svg.php(12): XF\Template\Templater->includeTemplate('public:sv_bbcod...', Array)
#13 src/XF/Template/Templater.php(1792): XF\Template\Templater->{closure}(Object(SV\LazyImageLoader\XF\Template\Templater), Array, NULL)
#14 src/addons/SV/SvgTemplate/svgRenderer.php(312): XF\Template\Templater->renderTemplate('sv_bbcode_modin...', Array, false)
#15 src/addons/SV/SvgTemplate/svgRenderer.php(246): SV\SvgTemplate\svgRenderer->renderTemplate('public:sv_bbcod...', NULL)
#16 src/XF/CssRenderer.php(135): SV\SvgTemplate\svgRenderer->renderTemplates(Array, Array, Array)
#17 src/XF/CssWriter.php(60): XF\CssRenderer->render(Array)
#18 src/addons/SV/SvgTemplate/svgWriter.php(47): XF\CssWriter->run(Array, 2, 1, '')
#19 svg.php(52): SV\SvgTemplate\svgWriter->run(Array, 2, 1, '', 1720282279)
#20 {main}

-------------

Previous Less_Exception_Compiler: The first argument to unit must be a number. - src/vendor/oyejorge/less.php/lib/Less/Functions.php:567
#0 src/vendor/oyejorge/less.php/lib/Less/Tree/Call.php(76): Less_Functions->unit(Object(XF\Less\Tree\HslColorVariable))
#1 src/vendor/oyejorge/less.php/lib/Less/Tree/Expression.php(46): Less_Tree_Call->compile(Object(Less_Environment))
#2 src/vendor/oyejorge/less.php/lib/Less/Tree/Value.php(25): Less_Tree_Expression->compile(Object(Less_Environment))
#3 src/vendor/oyejorge/less.php/lib/Less/Tree/Rule.php(76): Less_Tree_Value->compile(Object(Less_Environment))
#4 src/vendor/oyejorge/less.php/lib/Less/Tree/Ruleset.php(95): Less_Tree_Rule->compile(Object(Less_Environment))
#5 src/vendor/oyejorge/less.php/lib/Less/Parser.php(181): Less_Tree_Ruleset->compile(Object(Less_Environment))
#6 src/addons/SV/StandardLib/XF/CssRenderer.php(29): Less_Parser->getCss()
#7 src/addons/SV/RedisCache/XF/CssRenderer.php(216): SV\StandardLib\XF\CssRenderer->parseLessColorFuncValue('@someVar: unit(...', false)
#8 src/addons/SV/StandardLib/TemplaterHelper.php(527): SV\RedisCache\XF\CssRenderer->parseLessColorFuncValue('unit(lightness(...', false)
#9 src/XF/Template/Templater.php(1220): SV\StandardLib\TemplaterHelper->fnParseLessFunc(Object(SV\LazyImageLoader\XF\Template\Templater), false, 'unit(lightness(...')
#10 internal_data/code_cache/templates/l1/s2/public/sv_bbcode_modinterrupt_svg.css.php(16): XF\Template\Templater->func('parse_less_func', Array, false)
#11 src/XF/Template/Templater.php(1792): XF\Template\Templater->{closure}(Object(SV\LazyImageLoader\XF\Template\Templater), Array, NULL)
#12 src/XF/Template/Templater.php(1866): XF\Template\Templater->renderTemplate('sv_bbcode_modin...', Array)
#13 internal_data/code_cache/templates/l1/s2/public/sv_bbcode_modinterrupt_alert.svg.php(12): XF\Template\Templater->includeTemplate('public:sv_bbcod...', Array)
#14 src/XF/Template/Templater.php(1792): XF\Template\Templater->{closure}(Object(SV\LazyImageLoader\XF\Template\Templater), Array, NULL)
#15 src/addons/SV/SvgTemplate/svgRenderer.php(312): XF\Template\Templater->renderTemplate('sv_bbcode_modin...', Array, false)
#16 src/addons/SV/SvgTemplate/svgRenderer.php(246): SV\SvgTemplate\svgRenderer->renderTemplate('public:sv_bbcod...', NULL)
#17 src/XF/CssRenderer.php(135): SV\SvgTemplate\svgRenderer->renderTemplates(Array, Array, Array)
#18 src/XF/CssWriter.php(60): XF\CssRenderer->render(Array)
#19 src/addons/SV/SvgTemplate/svgWriter.php(47): XF\CssWriter->run(Array, 2, 1, '')
#20 svg.php(52): SV\SvgTemplate\svgWriter->run(Array, 2, 1, '', 1720282279)
#21 {main}

Request state

array(4) {
  ["url"] => string(57) "/data/svg/2/1/1720282279/sv_bbcode_modinterrupt_alert.svg"
  ["referrer"] => string(476) "/css.php?css=public%3Abb_code.less%2Cpublic%3Adbtech_shop.less%2Cpublic%3Adbtech_shop_postbit.less%2Cpublic%3Aeditor.less%2Cpublic%3Alightbox.less%2Cpublic%3Amessage.less%2Cpublic%3Anotices.less%2Cpublic%3Ashare_controls.less%2Cpublic%3Asiropu_ads_manager_ad.less%2Cpublic%3Astructured_list.less%2Cpublic%3AsvLazyImageLoader.less%2Cpublic%3Asv_bbcode_modinterrupt.less%2Cpublic%3Aextra.less&s=2&l=1&d=1720282279&k=c048f6595aba8703c7daebcd13bb9ac2c28845d7"
  ["_GET"] => array(4) {
    ["svg"] => string(28) "sv_bbcode_modinterrupt_alert"
    ["s"] => string(1) "2"
    ["l"] => string(1) "1"
    ["d"] => string(10) "1720282279"
  }
  ["_POST"] => array(0) {
  }
}
 
That error is unrelated to this add-on.

It is actually an issue with my Advanced bb-codes pack add-on usage of a template function (parse_less_func) added by in this add-on. Will look into it, but a lot of my add-ons are still not fully ready for XF2.3
 
Is there anyone who can help me with this as I don't have enough knowledge regarding server administration?

here is the redis status

1721289000848.webp


I installed the addon and my config is

Code:
<?php

$config['db']['host'] = 'localhost';
$config['db']['port'] = '3306';
$config['db']['username'] = '*****';
$config['db']['password'] = '*****';
$config['db']['dbname'] = '*****';

$config['fullUnicode'] = true;
$config['enableAddOnArchiveInstaller'] = true;


$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
    'server' => '127.0.0.1',
    'port' => 6379,
];

And site shows like this
1721289120185.webp
 
Last edited:
You need to enable debug mode in XenForo so it'll display the error message (do not leave it enabled!).

You can also try disabling the redis bits to see if that lets you into the admincp to view the XF error log.
 
You need to enable debug mode in XenForo so it'll display the error message (do not leave it enabled!).

You can also try disabling the redis bits to see if that lets you into the admincp to view the XF error log.
on debug mode enabled it shows

Code:
Fatal error: Uncaught RedisException: OOM command not allowed when used memory > 'maxmemory'. in /home/mydomain.com/public_html/src/addons/SV/RedisCache/Credis/Client.php:1370 Stack trace: #0 /home/mydomain.com/public_html/src/addons/SV/RedisCache/Credis/Client.php(1370): Redis->set('...', '...', 3600) #1 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/Redis.php(210): Credis_Client->__call('...', Array) #2 /home/mydomain.com/public_html/src/addons/SV/RedisCache/Traits/CacheTiming.php(72): SV\RedisCache\DoctrineCache\Redis->SV\RedisCache\DoctrineCache\{closure}() #3 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/Redis.php(200): SV\RedisCache\DoctrineCache\Redis->redisQueryForStatDebugPhp73('...', Object(Closure)) #4 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/CacheProvider.php(91): SV\RedisCache\DoctrineCache\Redis->doSave('...', Array, 3600) #5 /home/mydomain.com/public_html/src/XF/DataRegistry.php(189): SV\RedisCache\DoctrineCache\CacheProvider->save('...', Array, 3600) #6 /home/mydomain.com/public_html/src/XF/DataRegistry.php(158): XF\DataRegistry->setInCache('...', Array) #7 /home/mydomain.com/public_html/src/XF/DataRegistry.php(84): XF\DataRegistry->readFromDb(Array, Array) #8 /home/mydomain.com/public_html/src/XF/DataRegistry.php(228): XF\DataRegistry->get(Array) #9 /home/mydomain.com/public_html/src/XF/App.php(1929): XF\DataRegistry->offsetGet('...') #10 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #11 /home/mydomain.com/public_html/src/XF/App.php(1595): XF\Container->offsetGet('...') #12 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #13 /home/mydomain.com/public_html/src/XF/App.php(2978): XF\Container->offsetGet('...') #14 /home/mydomain.com/public_html/src/XF/App.php(3009): XF\App->extension() #15 /home/mydomain.com/public_html/src/XF/App.php(381): XF\App->extendClass('...') #16 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #17 /home/mydomain.com/public_html/src/XF/App.php(233): XF\Container->offsetGet('...') #18 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #19 /home/mydomain.com/public_html/src/XF/App.php(2598): XF\Container->offsetGet('...') #20 /home/mydomain.com/public_html/src/XF/Error.php(431): XF\App->request() #21 /home/mydomain.com/public_html/src/XF/Error.php(385): XF\Error->getExceptionTraceHtml(Object(CredisException)) #22 /home/mydomain.com/public_html/src/XF/App.php(2501): XF\Error->displayFatalExceptionMessage(Object(CredisException)) #23 /home/mydomain.com/public_html/src/XF.php(203): XF\App->displayFatalExceptionMessage(Object(CredisException)) #24 [internal function]: XF::handleException(Object(CredisException)) #25 {main} Next CredisException: OOM command not allowed when used memory > 'maxmemory'. in /home/mydomain.com/public_html/src/addons/SV/RedisCache/Credis/Client.php:1391 Stack trace: #0 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/Redis.php(210): Credis_Client->__call('...', Array) #1 /home/mydomain.com/public_html/src/addons/SV/RedisCache/Traits/CacheTiming.php(72): SV\RedisCache\DoctrineCache\Redis->SV\RedisCache\DoctrineCache\{closure}() #2 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/Redis.php(200): SV\RedisCache\DoctrineCache\Redis->redisQueryForStatDebugPhp73('...', Object(Closure)) #3 /home/mydomain.com/public_html/src/addons/SV/RedisCache/DoctrineCache/CacheProvider.php(91): SV\RedisCache\DoctrineCache\Redis->doSave('...', Array, 3600) #4 /home/mydomain.com/public_html/src/XF/DataRegistry.php(189): SV\RedisCache\DoctrineCache\CacheProvider->save('...', Array, 3600) #5 /home/mydomain.com/public_html/src/XF/DataRegistry.php(158): XF\DataRegistry->setInCache('...', Array) #6 /home/mydomain.com/public_html/src/XF/DataRegistry.php(84): XF\DataRegistry->readFromDb(Array, Array) #7 /home/mydomain.com/public_html/src/XF/DataRegistry.php(228): XF\DataRegistry->get(Array) #8 /home/mydomain.com/public_html/src/XF/App.php(1929): XF\DataRegistry->offsetGet('...') #9 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #10 /home/mydomain.com/public_html/src/XF/App.php(1595): XF\Container->offsetGet('...') #11 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #12 /home/mydomain.com/public_html/src/XF/App.php(2978): XF\Container->offsetGet('...') #13 /home/mydomain.com/public_html/src/XF/App.php(3009): XF\App->extension() #14 /home/mydomain.com/public_html/src/XF/App.php(381): XF\App->extendClass('...') #15 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #16 /home/mydomain.com/public_html/src/XF/App.php(233): XF\Container->offsetGet('...') #17 /home/mydomain.com/public_html/src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container)) #18 /home/mydomain.com/public_html/src/XF/App.php(2598): XF\Container->offsetGet('...') #19 /home/mydomain.com/public_html/src/XF/Error.php(431): XF\App->request() #20 /home/mydomain.com/public_html/src/XF/Error.php(385): XF\Error->getExceptionTraceHtml(Object(CredisException)) #21 /home/mydomain.com/public_html/src/XF/App.php(2501): XF\Error->displayFatalExceptionMessage(Object(CredisException)) #22 /home/mydomain.com/public_html/src/XF.php(203): XF\App->displayFatalExceptionMessage(Object(CredisException)) #23 [internal function]: XF::handleException(Object(CredisException)) #24 {main} thrown in /home/mydomain.com/public_html/src/addons/SV/RedisCache/Credis/Client.php on line 1391
 
1721307942434.webp

After adding this

It seems its working, now.

I'll test it on my live main domain is there any problem If I use it on multiple domain?

Thanks.
 
@Xon My previous config is this one.

Code:
<?php

$config['db']['host'] = 'localhost';
$config['db']['port'] = '3306';
$config['db']['username'] = '*****';
$config['db']['password'] = '******';
$config['db']['dbname'] = '******';
$config['enableLoginCsrf'] = false;

$config['fullUnicode'] = true;
$config['enableAddOnArchiveInstaller'] = true;
$config['removeThemeHouseBranding'] = true;

// Brotli compression is preferred over Gzip
$config ['enableGzip'] = false;

// Cache configuration

// $config['development']['enabled'] = true;

$config['cache']['enabled'] = true;
$config['cache']['css']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
        'server' => [
            ['127.0.0.1',11211]
        ]
    ];
    
// Page cache configuration
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 43200;
$config['cache']['context']['page']['provider'] = 'Memcached';
$config['cache']['context']['page']['config'] = [
        'server' => [
            ['127.0.0.1',11211]
        ]
    ];

// Optimizing Phone using Browser Detection addon by Xon

$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};

and current config is



Code:
<?php

$config['db']['host'] = 'localhost';
$config['db']['port'] = '3306';
$config['db']['username'] = '******';
$config['db']['password'] = '******';
$config['db']['dbname'] = '******';
$config['enableLoginCsrf'] = false;

$config['fullUnicode'] = true;
$config['enableAddOnArchiveInstaller'] = true;
$config['removeThemeHouseBranding'] = true;

// Brotli compression is preferred over Gzip
$config ['enableGzip'] = false;

// Cache configuration

// $config['development']['enabled'] = true;

$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = [
    'server' => '127.0.0.1',
    'port' => 6379,
];

// Optimizing Phone using Browser Detection addon by Xon

$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};

It seems site is too much slower than previous.

Am I doing something wrong?
 
You don't have the page cache enabled
Code:
// Page cache configuration
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 43200;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = [
    'server' => '127.0.0.1',
    'port' => 6379,
];

is that right?
 
  • Like
Reactions: Xon

@Mouth my current config is this one.

Code:
<?php

$config['db']['host'] = 'localhost';
$config['db']['port'] = '3306';
$config['db']['username'] = '****';
$config['db']['password'] = '****';
$config['db']['dbname'] = '****';
$config['enableLoginCsrf'] = false;

$config['fullUnicode'] = true;
$config['enableAddOnArchiveInstaller'] = true;
$config['removeThemeHouseBranding'] = true;

// Brotli compression is preferred over Gzip
$config ['enableGzip'] = false;

// Redis Config

$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 43200;
$config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['context']['page']['config'] = [
    'server' => '127.0.0.1',
    'port' => 6379,
];

// Optimizing Phone using Browser Detection addon by Xon

$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};

@Xon Could you please verify that the configuration is optimal for page caching? If not, could you please make any necessary adjustments or additions?

Thank you for your assistance.
 
@Xon Are there any known issues using this with AWS ElastiCache serverless Redis OSS caches?

Getting the following:

Code:
CredisException: CROSSSLOT Keys in request don't hash to the same slot src/addons/SV/RedisCache/Credis/Client.php:1444
#0 src/addons/SV/RedisCache/DoctrineCache/Redis.php(141): Credis_Client->__call('mget', Array)
#1 src/addons/SV/RedisCache/Traits/CacheTiming.php(41): SV\RedisCache\DoctrineCache\Redis->SV\RedisCache\DoctrineCache\{closure}()
#2 src/addons/SV/RedisCache/DoctrineCache/Redis.php(138): SV\RedisCache\DoctrineCache\Redis->redisQueryForStat('gets', Object(Closure))
#3 src/addons/SV/RedisCache/DoctrineCache/CacheProvider.php(63): SV\RedisCache\DoctrineCache\Redis->doFetchMultiple(Array)
#4 src/addons/SV/RedisCache/XF/CssRenderer.php(266): SV\RedisCache\DoctrineCache\CacheProvider->fetchMultiple(Array)
#5 src/XF/CssRenderer.php(111): SV\RedisCache\XF\CssRenderer->getIndividualCachedTemplates(Array)
#6 src/XF/CssWriter.php(55): XF\CssRenderer->render(Array)
#7 src/addons/SV/RedisCache/XF/CssWriter.php(68): XF\CssWriter->run(Array, 8, 1, 'xxxx...')
#8 css.php(30): SV\RedisCache\XF\CssWriter->run(Array, 8, 1, 'xxxx...')
#9 {main}

relevant cache config:

PHP:
$redisHostConfig = [
    'host' => 'ssl://xxxx.use1.cache.amazonaws.com',
    'port' => 6379,
//    'database' => 1,
];
$redisCacheConfig = [
    'provider' => 'SV\RedisCache\Redis',
    'config' => $redisHostConfig,
];
$config['pageCache'] = [
    'enabled' => true,
    'recordSessionActivity' => false,
];
$config['cache'] = $redisCacheConfig + [
    'enabled' => true,
    'sessions' => true,
    'context' => [
        [...]
    ],
];

With this add-on disabled, and the provider set to redis things seem to function correctly as far as I can tell
 
Last edited:
@Xon Are there any known issues using this with AWS ElastiCache serverless Redis OSS caches?
Redis clustered mode isn't supported as mget and scan don't behave the same. A number of my add-ons have ended up using scan. Most of them can be replaced but I just haven't looked into it.

I don't think it would be much work to make the library fallback to just get instead of mget but I'ld need to know the config it needs to accept.

R
With this add-on disabled, and the provider set to redis things seem to function correctly as far as I can tell
Can you share a sample of what the XF config looks like for setting up AWS ElastiCache with redis?
 
Can you share a sample of what the XF config looks like for setting up AWS ElastiCache with redis?

Same as what I posted above, just with redis as the provider.

That said, it turns out that it actually wasn't doing anything so it wasn't working with the stock system either unfortunately. It was logging errors that SELECT isn't available in cluster mode (even if I don't specify a database ID) it just wasn't exposing those errors
 
Last edited:
  • Wow
Reactions: Xon
Back
Top Bottom