Skip to content

Commit b8eaae0

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: minor. refs symfony#14683 Add documentation about redis cache configuration
2 parents dc11d20 + ead414b commit b8eaae0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

components/cache/adapters/redis_adapter.rst

+18
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ In order to use tag-based invalidation, you can wrap your adapter in :class:`Sym
193193
$client = RedisAdapter::createConnection('redis://localhost');
194194
$cache = new RedisTagAwareAdapter($client);
195195

196+
Configuring Redis
197+
~~~~~~~~~~~~~~~~~
198+
199+
When using Redis as cache, you should configure the ``maxmemory`` and ``maxmemory-policy``
200+
settings. By setting ``maxmemory``, you limit how much memory Redis is allowed to consume.
201+
If the amount is too low, Redis will drop entries that would still be useful and you benefit
202+
less from your cache. Setting the ``maxmemory-policy`` to ``allkeys-lru`` tells Redis that
203+
it is ok to drop data when it runs out of memory, and to first drop the oldest entries (least
204+
recently used). If you do not allow Redis to drop entries, it will return an error when you
205+
try to add data when no memory is available. An example setting could look as follows:
206+
207+
.. code-block:: ini
208+
209+
maxmemory 100mb
210+
maxmemory-policy allkeys-lru
211+
212+
Read more about this topic in the offical `Redis LRU Cache Documentation`_.
196213

197214
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
198215
.. _`Redis server`: https://redis.io/
@@ -203,3 +220,4 @@ In order to use tag-based invalidation, you can wrap your adapter in :class:`Sym
203220
.. _`Predis Connection Parameters`: https://github.com/nrk/predis/wiki/Connection-Parameters#list-of-connection-parameters
204221
.. _`TCP-keepalive`: https://redis.io/topics/clients#tcp-keepalive
205222
.. _`Redis Sentinel`: https://redis.io/topics/sentinel
223+
.. _`Redis LRU Cache Documentation`: https://redis.io/topics/lru-cache

0 commit comments

Comments
 (0)