Back to Top

How to configure Redis Cache in Magento 2

Updated 28 January 2026

You can configure Magento Redis cache to handle page caching and backend data efficiently, improving store speed in Magento 2.

Magento 2 offers command-line options for configuring Redis page and default caching, which is the preferred method for initial setups in Magento 2 Caching.

Although you can edit the <Commerce-install-dir>app/etc/env.php file to configure caching, using the command line ensures better syntax validation and accuracy.

Before you begin, ensure that Redis is installed on your server to avoid configuration issues.

Now that Redis is installed, the next step is to configure it for Magento 2. After that, we will verify whether the cache is working correctly.

Searching for an experienced
Magento 2 Company ?
Find out More

Redis configuration for page-cache

Run the setup:config:set command and specify parameters for Redis page-cache
configuration.

bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-<parameter>=<value>...

Below are the following parameters, along with their default values:

  • --page-cache-redis-server=127.0.0.1: Specifies the fully qualified hostname, IP address, or a UNIX socket path for the Redis server. The default 127.0.0.1 assumes Redis is installed on the same server as Magento 2.
  • --page-cache-redis-port=6379: Defines the port Redis listens on, with the default being 6379.
  • --page-cache-redis-db=0: When using Redis for multiple cache types (e.g., default cache, page cache, session storage), assign a database 0 for the default cache, 1 for page cache, and 2 for session storage.
  • --page-cache-redis-password=: Enables a Redis password for added security.
  • --page-cache-redis-compress-data=0: Enables data compression for page cache (default: 1)
  • --page-cache-redis-compression-lib=: Compression library to use (gzip, lzf, or none; default: gzip)
  • --page-cache-redis-use-cluster: Enable Redis cluster support (default: 0)

Example command

The following example enables Redis page caching, sets the host to 127.0.0.1, and assigns the database number to 1. All other parameters are set to the default value.

bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1

Results

After running these commands, Magento 2 adds configuration to app/etc/env.php file.

'cache' => [
        'graphql' => [
            'id_salt' => 'VNZ0EJI6NJ4hcnWz4Tf900KHXsR0SdrV'
        ],
        'frontend' => [
            'default' => [
                'id_prefix' => '69d_'
            ],
            'page_cache' => [
                'id_prefix' => '69d_',
                'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis', // The Redis 
                'backend_options' => [
                    'server' => '127.0.0.1', // Your Redis server IP
                    'database' => '1', // Redis database for default
                    'port' => '6379', // Your Redis server port
                    'password' => '', 'your-redis-password', // Uncomment and set if you have a password
                    'compress_data' => '0',
                    'compression_lib' => ''
                ]
            ]
        ],
        'allow_parallel_generation' => false
    ],

Verify Redis connection

redis-cli monitor

Sample page-caching output:

redis-monitor-output

It monitors command logs for every processed command on Redis.

redis-cli ping

The ping command responds with PONG.

Verify Magento Redis Configuration

bin/magento cache:status

As a result, this command displays the status of all cache types and confirms whether Redis is being used.

Redis Performance Tuning
To achieve optimal performance with Redis in Magento 2, it is important to:

1. Configure Redis persistence settings in redis.conf:

save 900 1
save 300 10
save 60 10000

2. Set max memory policy:

maxmemory 2gb
maxmemory-policy allkeys-lru

3. Enable AOF persistence for better durability:

appendonly yes
appendfsync everysec

For high-traffic sites, consider Redis Sentinel or Redis Cluster for high availability.

This is how to configure Redis Cache in Magento 2.

Reference Redis Magento 2 doc

If you require technical support, feel free to email us at [email protected].

Additionally, explore a wide array of solutions to boost your store’s capabilities by visiting the Adobe Commerce modules section.

For expert advice or to create tailored features, hire Adobe Commerce Developers for your project.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home