This way sessions are stored in-memory, making the shop faster and use less IO than when using MySQL or files as session store.
Configure Magento 2 to store sessions in Redis
As Magento 2 is fully supporting Redis, there is no need to install additional extensions to configure Redis.
All you need to do is extend your
app/etc/env.php and flush your cache.
To enable session storage in Redis, extend your
/data/web/magento2/app/etc/env.php with the following snippet:
A complete env.php configuration example can be found over here
Now flush your cache:
rm -rf /data/web/magento2/var/cache/*
Enable second Redis instance for Sessions
We have made is possible to enable a second Redis instance more tailored for saving session data (more informatie can be found in our changelog)
To enable the second Redis instance for sessions you run the command:
redis_persistent_instance --value True
After enabling the second Redis instance you need to update the
/data/web/magento2/app/etc/env.php file and change the port value to
6378 instead of the default
6379. Furthermore you need to add the following line to your crontab:
* * * * * redis-cli -p 6378 bgsave
Test whether your sessions are actually stored in Redis
To verify whether your configuration is working properly, first clear your session store:
Now open the site in your browser and hit
F5 a few times or log in to the admin panel.
If all is well, no additional sessions files should be written to
/data/web/magento2/var/session, but instead to the Redis database:
redis-cli -n 2 keys \*
A quick note, when you run into the configured max memory limit make sure that the necessary Redis keys are set to volatile (ensure an expire). Otherwise the complete allocated configured memory will fill up and Redis will ‘crash’.
For troubleshooting and an extended howto, please check the manual on the Magento website