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

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

2 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

2 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

3 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

4 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

6 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

6 days ago