How to setup Redis on a nublue server
This guide outlines what Redis is, what Redis does and how to set this up on your nublue server for a Magento 2 website.
What Is Redis
Redis (REmote DIctionary Server) is an open-source, in-memory data store that can be used to manage your website(s) cache and sessions.
Redis has low latency and stores the data in memory (RAM), which eliminates requests having to access slower disk speed, meaning requests can be handled quicker.
How is Redis configured
We set up two instances of Redis, each on a separate port. The instance on port 6379 is persistent and remains populated after a system crash or restart. The 2nd instance on port 6380 is volatile, and information stored on this instance will be lost after a system restart.
We recommend configuring your store to use the instance on port 6379 for sessions and the instance on 6380 for default and/or full page cache. The reason for this is that losing your sessions data will be more detrimental to the customer experience than losing the cache, in the event that there are issues which force a restart.
Each Redis instance has 16 databases (by default) to choose from, numbered from 0 to 15. You should use a single service per site on each database so that you can flush the information stored in Redis for a specific service by flushing a single database. We’d also recommend keeping a note of which database you’ve used for which site and service.
Typically, we recommend using database 0 for sessions and database 1 for default cache. Then, if you are using full page cache, use database 2. If you are using Redis for development or other sites, it’s useful to start these services on database 15 and work backwards (14, 13, 12 and so on) to ensure that they’re as far away from your live sites as possible and the two do not get confused. You want to avoid a situation where you’re using the same database number for 2 separate sites/services at all costs.
How to configure Redis
Firstly the Redis service needs to be enabled. Whilst this is installed by default, to save resources, we do not have this enabled on our servers.
To enable this, please contact us at [email protected], with the server name you want this enabling for should this not already be enabled.
Once this is enabled you will need to make some changes to your Magento configuration file typically located app/etc/env.php. Magento’s guide : https://experienceleague.adobe.com/en/docs/commerce-operations/configuration-guide/cache/redis/config-redis may help where you can either run a Magento-based command using the command line to input the Redis configuration into your Magento configuration file, or manually edit the app/etc/env.php with these changes.
For each type of data (eg: sessions, default cache, full page cache) you want to store using Redis, you’ll need to specify the port number and database number. To summarise, our recommended configuration for Redis is:
- Redis on port 6379: sessions storage
- Redis on port 6380: default cache and full page cache storage
Within each instance, we then recommend:
- Database 0 - sessions
- Database 1 - default cache
- Database 2 - full page cache
Then once complete, you will need to flush your Magento cache to push the changes live.
php bin/magento cache:flush
Need any Assistance?
Should you wish for us to setup Redis for your Magento site, please do get in touch and we can provide you a quote on setting this up for you.
Useful Redis Commands
Redis has the ability to manage it’s settings, view it’s data all with the use of its command:
redis-cli
The MONITOR command can let you look at what Redis is doing. Below is a useful command allowing you to check what is happening on a particular port and specified Redis database.
redis-cli -p -n MONITOR
The FLUSHALL command will flush sessions, cache, and page cache if the port and the specific databases are not selected. This can be useful should some data remain to be seen following a change, as the data may be cached.
redis-cli FLUSHALL