Join the community today
Become a Member

Xenforo Making the best use of Redis for Xenforo 2?

Discussion in 'Forum software usage' started by Jon Snow, Feb 4, 2019.

  1. Jon Snow

    Jon Snow Active Member

    437
    65
    28
    Jun 30, 2017
    Ratings:
    +103
    Local Time:
    11:31 AM
    Nginx 1.13.9
    MariaDB 10.1.31
    I'm setting up an xenForo 2 site just to play with it a bit to get a feel for it. I was wondering, what's the best way to use Redis with CMM? What would I put in my config.php file or should I just install Xon's add-on?
     
  2. Sunka

    Sunka Well-Known Member

    1,103
    299
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +481
    Local Time:
    4:31 PM
    Nginx 1.15.8
    MariaDB 10.3.12
    Of course you have to install @Xon addon, it is easier and better than without it.
    Put something like this in config.php

    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' => 2,
    'read_timeout' => 1,
    'timeout' => 1,
    'serializer' => 'igbinary',
    );
    // END Redis configuration //
     
    • Like Like x 1
    • Informative Informative x 1
  3. Jon Snow

    Jon Snow Active Member

    437
    65
    28
    Jun 30, 2017
    Ratings:
    +103
    Local Time:
    11:31 AM
    Nginx 1.13.9
    MariaDB 10.1.31
    @Sunka how is it better? What's the difference?
     
  4. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    straight from @Xon himself when asked about difference Redis Cache By Xon
     
    • Like Like x 2
  5. Jon Snow

    Jon Snow Active Member

    437
    65
    28
    Jun 30, 2017
    Ratings:
    +103
    Local Time:
    11:31 AM
    Nginx 1.13.9
    MariaDB 10.1.31
    @eva2000 Doesn't CMM install the php-redis extension by default? Wouldn't I have to install the redis server via yum anyway if I choose to use either?

    What are you planning to use when you upgrade this forum, Eva?
     
  6. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    yes centmin mod 123.09beta01 and newer install redis php extension out of the box and all you would need is to install redis server via remi yum repo as outlined at Upgrade - Nginx - Insight Guide - How to install Redis server on Centmin Mod LEMP stack :)

    For this forum will be a while before i update to XF 2.1.0 waiting on addons I use to mature or get support first.
     
    • Like Like x 1
  7. Jon Snow

    Jon Snow Active Member

    437
    65
    28
    Jun 30, 2017
    Ratings:
    +103
    Local Time:
    11:31 AM
    Nginx 1.13.9
    MariaDB 10.1.31
    I understand that but what are you considering when you do upgrade to 2.0+? Or have you never thought about it yet?
     
  8. Sunka

    Sunka Well-Known Member

    1,103
    299
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +481
    Local Time:
    4:31 PM
    Nginx 1.15.8
    MariaDB 10.3.12
    @eva2000
    I am planing to upgrade to xf 2.1 and use redis with several instances for cache

    First, how to run your script (downloading first all from github? and put in /usr/local/src/centminmod/addons/ or /root/tools/)?
    Could you give me correct command?

    I have default redis server, so only default port 6379
    I need to create 2 more for caching pages and css (css will be enabled in future)

    6379 will be for classic xf cache
    6479 will be for xf guest page cache
    6480 will be for xf css cache (not enabled at beginning)

    Because 6479 and 6480 are new separate Redis server instances to be used for caching only without ondisk data persistence, why in xf conf for redish cache you use 'persistent' => true

    My conf will be like this (I am using xon addon).
    there is some differences from xf 2.0 (server => host)
    Is this look allright?
    css cache is disabled OK?

    PHP:
    // START Redis configuration //

    // Global Cache
    $config['cache']['enabled'] = true;
    $config['cache']['sessions'] = true;
    $config['cache']['namespace'] = 'xfredis_';
    $config['cache']['provider'] = 'SV\RedisCache\Redis';
    $config['cache']['config'] = [
        
    'host' => '127.0.0.1',
        
    'port' => 6379,
        
    'connect_retries' => 2,
        
    'use_lua' => true,
        
    'compress_data' => 2,
        
    'serializer' => 'igbinary',
    //  'password' => 'password',
        
    'timeout' => 0,
        
    'persistent' => true,
        
    'persistent_id' => 'global'
    ];


    // Guest Page Cache
    $config['pageCache']['enabled'] = true;
    $config['pageCache']['lifetime'] = 900;
    $config['pageCache']['recordSessionActivity'] = true;
    $config['cache']['context']['page']['namespace'] = 'xfredispages_';
    $config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
    $config['cache']['context']['page']['config'] = [
        
    'host' => '127.0.0.1',
        
    'port' => 6479,
        
    'connect_retries' => 2,
        
    'use_lua' => true,
        
    'compress_data' => 6,
        
    'serializer' => 'igbinary',
        
    'timeout' => 1,
        
    'persistent' => true,
        
    'persistent_id' => 'pages'
    ];

    // css cache
    // $config['css']['enabled'] = true;
    $config['cache']['context']['css']['provider'] = 'Redis';
    $config['cache']['context']['css']['config'] = [
        
    'host' => '127.0.0.1',
        
    'port' => 6480,
        
    'connect_retries' => 2,
        
    'use_lua' => true,
        
    'compress_data' => 6,
        
    'serializer' => 'igbinary',
        
    'timeout' => 1,
        
    'persistent' => true,
        
    'persistent_id' => 'css'
    ];

    // END Redis configuration //
     
  9. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    consideration is solely addon compatibility but test cloned forum instance for testing upgrades is what i do so can see when it's the right time.

    As to best use of redis for Xenforo 2.1 see Xenforo - Xenforo 2.1.0 Beta 1 Install & 2.1.0 Final Upgrade On Centmin Mod 123.09beta01 LEMP Stack

    the script is located at centminmod/centminmod-redis for redis-generator.sh and it's provided as is without support so you just download the script give it 0755 permissions and run it. You can do a git clone into /root/tools too

    persistent setting is for connection to redis not the ondisk persistence that is different

    You seem to be use Xon redis addon so you'd have to figure out via testing it that works.
     
    • Like Like x 1
  10. Sunka

    Sunka Well-Known Member

    1,103
    299
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +481
    Local Time:
    4:31 PM
    Nginx 1.15.8
    MariaDB 10.3.12
    @eva2000

    You wrote:
    Something is not clear to me.
    I have redis with 3 separate instances.
    6379 global xf cache
    6480 xf guest page cache
    6481 will be for xf css cache (not enabled at the moment).

    This 3 instances use same redis database if my conf is like this?
    PHP:
    // START Redis configuration //

    // Global Cache
    $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' => 2,
        
    'serializer' => 'igbinary',
    //  'password' => 'password',
        
    'read_timeout' => 1,
        
    'timeout' => 1,
        
    'persistent' => true,
        
    'persistent_id' => 'global'
    );


    // Guest Page Cache
    $config['pageCache']['enabled'] = true;
    $config['pageCache']['lifetime'] = 900;
    $config['pageCache']['recordSessionActivity'] = true;
    $config['cache']['context']['page']['namespace'] = 'xfredispages_';
    $config['cache']['context']['page']['provider'] = 'SV\RedisCache\Redis';
    $config['cache']['context']['page']['config'] = array(
        
    'server' => '127.0.0.1',
        
    'port' => 6480,
        
    'connect_retries' => 2,
        
    'use_lua' => true,
        
    'compress_data' => 6,
        
    'serializer' => 'igbinary',
        
    'timeout' => 1,
        
    'persistent' => true,
        
    'persistent_id' => 'pages'
    );

    // css cache
    // $config['css']['enabled'] = true;
    //$config['cache']['context']['css']['provider'] = 'Redis';
    //$config['cache']['context']['css']['config'] = array(
    //    'server' => '127.0.0.1',
    //    'port' => 6481,
    //   'connect_retries' => 2,
    //    'use_lua' => true,
    //    'compress_data' => 6,
    //    'serializer' => 'igbinary',
    //    'timeout' => 1,
    //    'persistent' => true,
    //    'persistent_id' => 'css'
    //);

    // END Redis configuration //
    my questions:

    If I just add 'database' => 2 to global cache and 4 to guest page cache and 7 in last one, then restart redis and then redis will use 3 different databases or not?

    Why you disabled option 'persistent' => true in your conf

    Will command redis-cli flushall delete all 3 databases/instances or just default one?

    Regarding session cache, is it wise to put session on isolate istance? Or it not possible or will lead to errors.
    Like this:

    Code:
    // session cache
    $config['cache']['sessions'] = true;
    $config['cache']['context']['sessions']['provider'] = 'SV\RedisCache\Redis';
    $config['cache']['context']['sessions']['config'] = array(
        'server' => '127.0.0.1',
        'port' => 6481,
        'connect_retries' => 2,
        'use_lua' => true,
        'compress_data' => 6,
        'serializer' => 'igbinary',
        'timeout' => 1,
        'persistent' => true,
        'persistent_id' => 'session'
    );
    Enabling css cache will lead to problems if I change something with css and have to wait to cache expire change to see change?
     
  11. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    yup
    xon said persistent option could be less stable and i am getting 404/timeout on webpagetest repeated tests on and off so thought i'd disable it for troubleshooting

    nope see redis-cli help command

    i.e. for default 6379, 6479 and 6480
    Code (Text):
    redis-cli flushall
    redis-cli -h 127.0.0.1 -p 6479 flushall
    redis-cli -h 127.0.0.1 -p 6480 flushall
    

    left session cache alone for now - test and see

    css gets cached with xon's redis cache without setting it up in src/config.php unlike xenforo 2.1 native css cache context. IIRC it's 60 min cache time. If you setup separate css cache, you can just clear that specific redis database number in specific redis instance or just do flushall right after css edit/updates.
     
    • Like Like x 1
  12. Sunka

    Sunka Well-Known Member

    1,103
    299
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +481
    Local Time:
    4:31 PM
    Nginx 1.15.8
    MariaDB 10.3.12
    So right now I have 3 instances (default + 2 more) sharing one database?

    OK, If I add to every instance database (2,4,7 or could be different numbers aka 2,3,4) what is with default one (0) port 6379.
    Also where is conf for instances to set up memory for each one in var/run/redis/redis6480.sock end so on?

    And just to be sure, redis-cli flushall will empty just default (0) database or any database on default port
     
  13. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    if you don't specify the database number, redis will use same default database number = 0

    will empty all databases 0 to 15 on the port redis instance is listening to unless you specify database number via -n option
    empty database 2 on all 3 redis instances
    Code (Text):
    redis-cli -n 2 flushall
    redis-cli -h 127.0.0.1 -p 6479 -n 2 flushall
    redis-cli -h 127.0.0.1 -p 6480 -n 2 flushall
    
     
    • Like Like x 1
  14. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    from Xenforo - Xenforo 2.1.0 Beta 1 Install & 2.1.0 Final Upgrade On Centmin Mod 123.09beta01 LEMP Stack and centminmod/centminmod-redis

    using redis-generator.sh multi or multi-cache option
     
  15. rdan

    rdan Well-Known Member

    4,671
    1,121
    113
    May 25, 2014
    Ratings:
    +1,663
    Local Time:
    10:31 PM
    Mainline
    10.2
    Link about this?
    Curious on why it isn't stable.

    It helped me: Redis Cache By Xon
    With 9k online users XF2.0 forum.
     
  16. eva2000

    eva2000 Administrator Staff Member

    41,723
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:31 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    i am just going by repeat runs of webpagetest.org and error i am seeing - not sure if it's wpt end of xenforo 2.1.0 end right now. Normal browser access/visits are fine though.

    xf2.1.0-redis-cache-error-wpt-02.png xf2.1.0-redis-cache-error-wpt-03.png

    and @Xon's FAQ Redis Cache By Xon - Extra info though that could be dated now as redis php extension has updated since then
     
    • Informative Informative x 1
  17. klimbo

    klimbo New Member

    8
    1
    1
    Mar 6, 2019
    Ratings:
    +1
    Local Time:
    12:31 AM
    CentOS 6.5 64bit
    MariaDB 5.5
    i dislike css i think no nothing push me to use css