Skip to content

[FEATURE] Allow key prefix for Redis keys #1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TYPO3IncTeam opened this issue Sep 10, 2024 · 0 comments
Open

[FEATURE] Allow key prefix for Redis keys #1023

TYPO3IncTeam opened this issue Sep 10, 2024 · 0 comments
Labels

Comments

@TYPO3IncTeam
Copy link
Collaborator

ℹ️ View this commit on Github
👥 Authored by Markus Klein [email protected]
✔️ Merged by Benni Mack [email protected]

Commit message

[FEATURE] Allow key prefix for Redis keys

Adds the possibility to configure Redis key prefixes
for cache and session backends, which allows to use
the same Redis database for multiple caches and/or
TYPO3 instances.

Resolves: #104451
Releases: main
Change-Id: Id6aa2f7ba9a4a0dbfb2335150602aeb836e09b90
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85324
Tested-by: Benni Mack [email protected]
Tested-by: core-ci [email protected]
Tested-by: Stefan Bürk [email protected]
Reviewed-by: Benni Mack [email protected]
Reviewed-by: Stefan Bürk [email protected]

➕ Added files

13.3/Feature-104451-RedisBackendsSupportForKeyPrefixing.rst
.. include:: /Includes.rst.txt

.. _feature-104451-1721646565:

===========================================================
Feature: #104451 - Redis backends support for key prefixing
===========================================================

See :issue:`104451`

Description
===========

It is now possible to add a dedicated key prefix for all invocations of a Redis
cache or session backend. This allows to use the same Redis database for multiple
caches or even for multiple TYPO3 instances if the provided prefix is unique.

Possible use cases are:

* Using Redis caching for multiple caches, if only one Redis database is available
* Pre-fill caches upon deployments using a new prefix (zero downtime deployments)

..  code-block:: php
    :caption: additional.php example for using Redis as session backend

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['BE'] = [
        'backend' => \TYPO3\CMS\Core\Session\Backend\RedisSessionBackend::class,
        'options' => [
            'hostname' => 'redis',
            'database' => '11',
            'compression' => true,
            'keyPrefix' => 'be_sessions_',
        ],
    ];
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['session']['FE'] = [
        'backend' => \TYPO3\CMS\Core\Session\Backend\RedisSessionBackend::class,
        'options' => [
            'hostname' => 'redis',
            'database' => '11',
            'compression' => true,
            'keyPrefix' => 'fe_sessions_',
            'has_anonymous' => true,
        ],
    ];

..  code-block:: php
    :caption: additional.php example for pages cache

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['pages']['backend'] = \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['pages']['options']['hostname'] = 'redis';
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['pages']['options']['database'] = 11;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['pages']['options']['compression'] = true;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['pages']['options']['keyPrefix'] = 'pages_';

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['rootline']['backend'] = \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['rootline']['options']['hostname'] = 'redis';
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['rootline']['options']['database'] = 11;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['rootline']['options']['compression'] = true;
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['rootline']['options']['keyPrefix'] = 'rootline_';

Impact
======

The new feature allows to use the same Redis database for multiple caches or even
for multiple TYPO3 instances while having no impact on existing configuration.

..  attention::
    If you start using the same Redis database for multiple caches or
    using the same database also for session storage, make sure any involved
    cache configuration uses **a unique key prefix**.
    If only one of the caches does not use a key prefix, any cache flush
    operation will always flush the whole database, hence also all other caches/sessions.

.. index:: Frontend, LocalConfiguration, ext:core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant