CraftCMS redis caching and session handling (Unix Socket)

Redis can enhance the performance of (busier) CraftCMS website and shops. We recommand a configuration as following, which will use redis for caching and a redis persistent instance for the sessions (over unix socket files).

More info here about the Redis setup: https://portal.hosted-power.com/knowledgebase/article/112/redis-server/

Add redis caching component

composer require --prefer-dist yiisoft/yii2-redis

Modify config/app.php

 [
           'class' => yii\redis\Cache::class,
           'defaultDuration' => 86400,
           'redis' => [
                'unixSocket' => '/var/run/redis/redis.sock',
                'database' => 1,
            ],
        ],
        'session' => [
            'class' => yii\redis\Session::class,
            'as session' => [
                'class' => \craft\behaviors\SessionBehavior::class,
            ],
            'redis' => [
                  'unixSocket' => '/var/run/redis-persistent/redis.sock',
                  'database' => 1,
            ],
        ],
    ],
]
...


Was this article helpful?

mood_bad Dislike 6
mood Like 2
visibility Views: 40923