Skip to content

olivertar/m2_redis_patch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Magento 2 Redis session patch

Redis patch for session management optimization

Compatible with

  • Magento 2.4.8
  • php-redis-session-abstract 2.1.2

Installation

To install patches with composer you need to have "cweagans/composer-patches" installed first. If you don't have it installed you can do it with:

composer require cweagans/composer-patches

Then, add the patches to your composer.json

"extra": {
    "magento-force": "override",
    "patches": {
        "magento/framework": {
            "Serialize session": "https://raw.githubusercontent.com/olivertar/m2_redis_patch/refs/heads/main/patches/colinmollenhour/php-redis-session-abstract/2.1.2/set-php-serialize-handler.patch"
        },
        "colinmollenhour/php-redis-session-abstract": {
            "Session lock write only": "https://raw.githubusercontent.com/olivertar/m2_redis_patch/refs/heads/main/patches/colinmollenhour/php-redis-session-abstract/2.1.2/implement-write-lock.patch"
        }
    }
}

Then run the commands

composer install
bin/magento setup:upgrade --keep-generated

What is this patch?

When using Redis as session storage in Magento 2, simultaneous or closely spaced requests to the same session can end up queued due to the locking system that prevents concurrent writes.

This behavior is particularly affecting environments with multiple AJAX calls (such as checkout) or headless frontends, generating unnecessary delays even when most requests only read the session and do not modify it.

To improve performance, Yonn Trimoreau developed a patch for the colinmollenhour/php-redis-session-abstract library used by Magento 2, which restricts the use of locks to write operations only. This significantly reduces latency in high-concurrency scenarios.

This repository includes a customized version of this patch, compatible with Magento 2.4.8 and version 2.1.2 of the aforementioned library.

Acknowledgments

  • To Colin Mollenhour for creating and maintaining this library for the entire PHP community.
  • To Rostislav Suleimanov Who has masterfully explained the problem and the different options to mitigate it.
  • And finally to Yonn Trimoreau who has dedicated his time to solve the problem and has created the patch that I have adapted.

Recommended reading

About

Redis lock only on write operation

Resources

Stars

Watchers

Forks

Packages

No packages published