Skip to content

[Cache] Update redis_adapter.rst #18614

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

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions components/cache/adapters/redis_adapter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,8 @@ Available Options

.. _redis-tag-aware-adapter:

Working with Tags
-----------------

In order to use tag-based invalidation, you can wrap your adapter in :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter`, but when Redis is used as backend, it's often more interesting to use the dedicated :class:`Symfony\\Component\\Cache\\Adapter\\RedisTagAwareAdapter`. Since tag invalidation logic is implemented in Redis itself, this adapter offers better performance when using tag-based invalidation::

use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;

$client = RedisAdapter::createConnection('redis://localhost');
$cache = new RedisTagAwareAdapter($client);

Configuring Redis
~~~~~~~~~~~~~~~~~
-----------------

When using Redis as cache, you should configure the ``maxmemory`` and ``maxmemory-policy``
settings. By setting ``maxmemory``, you limit how much memory Redis is allowed to consume.
Expand All @@ -247,6 +236,21 @@ try to add data when no memory is available. An example setting could look as fo
maxmemory 100mb
maxmemory-policy allkeys-lru

Working with Tags
-----------------

In order to use tag-based invalidation, you can wrap your adapter in :class:`Symfony\\Component\\Cache\\Adapter\\TagAwareAdapter`, but when Redis is used as backend, it's often more interesting to use the dedicated :class:`Symfony\\Component\\Cache\\Adapter\\RedisTagAwareAdapter`. Since tag invalidation logic is implemented in Redis itself, this adapter offers better performance when using tag-based invalidation::

use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;

$client = RedisAdapter::createConnection('redis://localhost');
$cache = new RedisTagAwareAdapter($client);

.. note::

When using RedisTagAwareAdapter, in order to maintain relationships between tags and cache items, you have to use either ``noeviction`` or ``volatile-*`` in the Redis ``maxmemory-policy`` eviction policy.

Read more about this topic in the official `Redis LRU Cache Documentation`_.

.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
Expand Down