8000 minor #11364 [Cache] Show how to configure redis provider (Nyholm) · symfony/symfony-docs@737539a · GitHub
[go: up one dir, main page]

Skip to content

Commit 737539a

Browse files
committed
minor #11364 [Cache] Show how to configure redis provider (Nyholm)
This PR was squashed before being merged into the 3.4 branch (closes #11364). Discussion ---------- [Cache] Show how to configure redis provider This will properly fix #10989 Im not 100% confident on the xml configuration. @nicolas-grekas is this a good description of the Provider? Commits ------- 120a87e [Cache] Show how to configure redis provider
2 parents 533e511 + 120a87e commit 737539a

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

cache.rst

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ of:
3737
**Adapter**
3838
An adapter is a *template* that you use to create Pools.
3939
**Provider**
40-
A provider is the DSN connection to the actual storage.
40+
A provider is a service that some adapters are using to connect to the storage.
41+
Redis and Memcached are example of such adapters. If a DSN is used as the
42+
provider then a service is automatically created.
4143

4244
There are two pools that are always enabled by default. They are ``cache.app`` and
4345
``cache.system``. The system cache is use for things like annotations, serializer,
@@ -315,6 +317,83 @@ For advanced configurations it could sometimes be useful to use a pool as an ada
315317
],
316318
]);
317319
320+
Custom Provider Options
321+
-----------------------
322+
323+
Some providers have specific options that could be configured. The
324+
:doc:`RedisAdapter </components/cache/adapters/redis_adapter>` allows you to create
325+
providers with option ``timeout``, ``retry_interval`` etc. To use these options with non-default
326+
values you need to create your own ``\Redis`` provider and use that when configuring
327+
the pool.
328+
329+
.. configuration-block::
330+
331+
.. code-block:: yaml
332+
333+
# config/packages/cache.yaml
334+
framework:
335+
cache:
336+
pools:
337+
cache.my_redis:
338+
adapter: cache.adapter.redis
339+
provider: app.my_custom_redis_provider
340+
341+
services:
342+
app.my_custom_redis_provider:
343+
class: \Redis
344+
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
345+
arguments:
346+
- 'redis://localhost'
347+
- [ retry_interval: 2, timeout: 10 ]
348+
349+
.. code-block:: xml
350+
351+
<!-- config/packages/cache.xml -->
352+
<?xml version="1.0" encoding="UTF-8" ?>
353+
<container xmlns="http://symfony.com/schema/dic/services"
354+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
355+
xmlns:framework="http://symfony.com/schema/dic/symfony"
356+
xsi:schemaLocation="http://symfony.com/schema/dic/services
357+
https://symfony.com/schema/dic/services/services-1.0.xsd">
358+
359+
<framework:config>
360+
<framework:cache>
361+
<framework:pool name="cache.my_redis" adapter="cache.adapter.redis" provider="app.my_custom_redis_provider"/>
362+
</framework:cache>
363+
</framework:config>
364+
365+
<services>
366+
<service id="app.my_custom_redis_provider" class="\Redis">
367+
<argument>redis://localhost</argument>
368+
<argument type="collection">
369+
<argument key="retry_interval">2</argument>
370+
<argument key="timeout">10</argument>
371+
</argument>
372+
</service>
373+
</services>
374+
</container>
375+
376+
.. code-block:: php
377+
378+
// config/packages/cache.php
379+
$container->loadFromExtension('framework', [
380+
'cache' => [
381+
'pools' => [
382+
'cache.my_redis' => [
383+
'adapter' => 'cache.adapter.redis',
384+
'provider' => 'app.my_custom_redis_provider',
385+
],
386+
],
387+
],
388+
]);
389+
390+
$container->getDefinition('app.my_custom_redis_provider', \Redis::class)
391+
->addArgument('redis://localhost')
392+
->addArgument([
393+
'retry_interval' => 2,
394+
'timeout' => 10
395+
]);
396+
318397
Creating a Cache Chain
319398
----------------------
320399

0 commit comments

Comments
 (0)
0