Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use other session handler #3428

Closed
boboldehampsink opened this issue Apr 4, 2018 · 8 comments

Comments

Projects
None yet
4 participants
@boboldehampsink
Copy link
Contributor

commented Apr 4, 2018

There is no documentation on how to use a different session handler then yii\web\Session. Here's an example of how to use both the session handler and cache of yiisoft/yii2-redis with Craft 3:

    'components' => [
        'redis' => [
            'class' => yii\redis\Connection::class,
            'hostname' => $redis['host'],
            'port' => $redis['port'],
            'password' => $redis['pass'],
            'database' => 0,
        ],
        'session' => [
            'class' => yii\redis\Session::class,
            'as session' => [
                'class' => craft\behaviors\SessionBehavior::class,
            ],
        ],
        'cache' => [
            'class' => yii\redis\Cache::class,
            'defaultDuration' => 86400,
        ],
    ],
@timkelty

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

Holy cow, yes - please add to docs!

Was fumbling around until I found this…@boboldehampsink where did you even find docs for the as session thing?! You are superhuman!

Also answers this: https://github.com/craftcms/docs/issues/94

@timkelty

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

If you want to run your queue also from redis:

'components' => [
    'redis' => [
        'class' => \yii\redis\Connection::class,
        'hostname' => $redis['host'],
        'port' => $redis['port'],
        'password' => $redis['pass'],
        'database' => 0,
    ],
    'session' => [
        'class' => yii\redis\Session::class,
        'as session' => [
            'class' => \craft\behaviors\SessionBehavior::class,
        ],
    ],
    'cache' => [
        'class' => \yii\redis\Cache::class,
        'defaultDuration' => 86400,
    ],
    'queue' => [
        'class' => \yii\queue\redis\Queue::class,
        'channel' => 'queue',
    ]
]
@brandonkelly

This comment has been minimized.

Copy link
Member

commented Jul 31, 2018

Whoa I had no idea as X was a thing.

@khalwat

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

I've had an example up here for a bit too: https://github.com/nystudio107/craft/blob/master/config/app.php#L29

@boboldehampsink

This comment has been minimized.

Copy link
Contributor Author

commented Aug 3, 2018

Haha guys, its actually just here in the docs: https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors#attaching-behaviors

@timkelty does that prevent the craft_tasks table from being created?
@khalwat that looks a bit overkill

@timkelty

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

@boboldehampsink I swear I looked and couldn't find it…Way to read the manual!

does that prevent the craft_tasks table from being created?

Assuming you mean the queue table (Craft 3 name), yes, it prevents it from being used and uses Redis directly. (the table will always still be created from craft's installation process)

Only hang up is you'll miss out of the front-end progress indicator, until myself or someone writes something for redis that implements QueueInterface: #3171

@boboldehampsink

This comment has been minimized.

Copy link
Contributor Author

commented Aug 3, 2018

Ah cool. That doesn't really bother me as I always run tasks from the command line in a separate worker node to keep load off of the web node.

@timkelty

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2018

That doesn't really bother me as I always run tasks from the command line in a separate worker node to keep load off of the web node.

Same. But the front-end indicator can be nice so you know when something in the background is running, or when something failed.

I'm not yet sure about the performance gains from avoiding the DB and using redis for queue, but it seems like a good idea. Some jobs end up with thousands of steps, each of which have to hit the DB to update the progress.

@brandonkelly brandonkelly transferred this issue from another repository Nov 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.