Categories: How ToMagento 2

How to Setup & Use High Performance Redis In Magento 2 Database

Nowadays, Store owners are adopting the new & improved Magento 2.0 Environment because of its new design, security and optimized performance but still they keep looking for better ways to optimize Magento store. Enabling default cache management will help a bit to improve performance but another great way to boost website performance is to use faster backend cache system.

So, the next question arises is, what is faster & alternative cache system for Magento 2?
Answer is Redis.

What is Redis?
Among available all alternatives, Redis is an open source, in-memory data structure store, used as a database, cache and session storage. It provides very fast backend cache with full cache support that doesn’t require low-level file system cache and stable performance for high traffic Magento stores.

Advantages of Redis:

  • Provides extreme in-memory storage
  • Vertical & Horizontal Scaleable
  • Can be Shareable among Multiple Servers
  • Supports cache tag

Also, the requirements of Redis is very simple like.

  • Redis Server
  • PHP Redis Extension

Setting Up Redis as Cache Storage in Magento 2

Default Magento 2 Supports all Redis pre-requirement out of box so you don’t need to worry more, all you need to do is just add following code to your Magento Root/app/etc/env.php

'cache' =>
 array (
 'frontend' =>
 array (
  'default' =>
    array (
      'backend' => 'Cm_Cache_Backend_Redis',
          'backend_options' =>
        array (
          'server' => '127.0.0.1', or ‘localhost’,
          'port' => '6379',
             'persistent' => 0,
             'database' => '0',
             'force_standalone' => '0',
             'connect_retries' => '10',
             'read_timeout' => '30',
             'automatic_cleaning_factor' => '0',
          'compress_data' => '1',
             'compress_tags' => '1',
             'compress_threshold' => '20480',
             'compression_lib' => 'gzip',
      ),
  ),
  ),
),

Setting Up Redis as Session Storage in Magento 2

'session' =>
  array (
 'save' => 'redis',
 'redis' =>
    array (
     'host' => '127.0.0.1', or ‘localhost’,
     'port' => '6379',
     'password' => '',
     'timeout' => '5',
        'persistent_identifier' => '',
     'database' => '1',
        'compression_threshold' => '2048',
     'compression_library' => 'gzip',
     'log_level' => '1',
        'max_concurrency' => '6',
        'break_after_frontend' => '5',
        'break_after_adminhtml' => '30',
        'first_lifetime' => '600',
        'bot_first_lifetime' => '60',
     'bot_lifetime' => '7200',
        'disable_locking' => '0',
        'min_lifetime' => '60',
        'max_lifetime' => '2592000'
 )
)

By implementing above code, it will successfully install Redis and help you boosting your website performance. Let me know in the comment section if you have any ideas or issuse in implementing this code. I’ll be happy to help you!
Happy Coding!

Click to rate this post!
[Total: 5 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

8 hours ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

1 day ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

2 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

4 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

6 days ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago