8000 minor #16217 [Lock] Add new Doctrine DBAL stores (GromNaN) · symfony/symfony-docs@af8c0bf · GitHub
[go: up one dir, main page]

Skip to content

Commit af8c0bf

Browse files
committed
minor #16217 [Lock] Add new Doctrine DBAL stores (GromNaN)
This PR was merged into the 5.4 branch. Discussion ---------- [Lock] Add new Doctrine DBAL stores Fix #16215 #15952 #15950 #15945 #15970 Commits ------- 62ba2e4 [Lock] Add new Doctrine DBAL stores
2 parents d8d53a7 + 62ba2e4 commit af8c0bf

File tree

1 file changed

+87
-21
lines changed

1 file changed

+87
-21
lines changed

components/lock.rst

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,20 @@ Locks are created and managed in ``Stores``, which are classes that implement
350350

351351
The component includes the following built-in store types:
352352

353-
============================================ ====== ======== ======== =======
354-
Store Scope Blocking Expiring Sharing
355-
============================================ ====== ======== ======== =======
356-
:ref:`FlockStore <lock-store-flock>` local yes no yes
357-
:ref:`MemcachedStore <lock-store-memcached>` remote no yes no
358-
:ref:`MongoDbStore <lock-store-mongodb>` remote no yes no
359-
:ref:`PdoStore <lock-store-pdo>` remote no yes no
360-
:ref:`PostgreSqlStore <lock-store-pgsql>` remote yes no yes
361-
:ref:`RedisStore <lock-store-redis>` remote no yes yes
362-
:ref:`SemaphoreStore <lock-store-semaphore>` local yes no no
363-
:ref:`ZookeeperStore <lock-store-zookeeper>` remote no no no
364-
============================================ ====== ======== ======== =======
353+
========================================================= ====== ======== ======== =======
354+
Store Scope Blocking Expiring Sharing
355+
========================================================= ====== ======== ======== =======
356+
:ref:`FlockStore <lock-store-flock>` local yes no yes
357+
:ref:`MemcachedStore <lock-store-memcached>` remote no yes no
358+
:ref:`MongoDbStore <lock-store-mongodb>` remote no yes no
359+
:ref:`PdoStore <lock-store-pdo>` remote no yes no
360+
:ref:`DoctrineDbalStore <lock-store-dbal>` remote no yes no
361+
:ref:`PostgreSqlStore <lock-store-pgsql>` remote yes no yes
362+
:ref:`DoctrineDbalPostgreSqlStore <lock-store-dbal-pgsql>` remote yes no yes
363+
:ref:`RedisStore <lock-store-redis>` remote no yes yes
364+
:ref:`SemaphoreStore <lock-store-semaphore>` local yes no no
365+
:ref:`ZookeeperStore <lock-store-zookeeper>` remote no no no
366+
========================================================= ====== ======== ======== =======
365367

366368
.. _lock-store-flock:
367369

@@ -471,13 +473,13 @@ MongoDB Connection String:
471473
PdoStore
472474
~~~~~~~~
473475

474-
The PdoStore saves locks in an SQL database. It requires a `PDO`_ connection, a
475-
`Doctrine DBAL Connection`_, or a `Data Source Name (DSN)`_. This store does not
476+
The PdoStore saves locks in an SQL database. It is identical to DoctrineDbalStore but requires
477+
a `PDO`_ connection or a `Data Source Name (DSN)`_. This store does not
476478
support blocking, and expects a TTL to avoid stalled locks::
477479

478480
use Symfony\Component\Lock\Store\PdoStore;
479481

480-
// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
482+
// a PDO or DSN for lazy connecting through PDO
481483
$databaseConnectionOrDSN = 'mysql:host=127.0.0.1;dbname=app';
482484
$store = new PdoStore($databaseConnectionOrDSN, ['db_username' => 'myuser', 'db_password' => 'mypassword']);
483485

@@ -491,21 +493,56 @@ You can also create this table explicitly by calling the
491493
:method:`Symfony\\Component\\Lock\\Store\\PdoStore::createTable` method in
492494
your code.
493495

496+
.. deprecated:: 5.4
497+
498+
Using ``PdoStore`` with Doctrine DBAL is deprecated in Symfony 5.4. Use ``DoctrineDbalStore`` instead.
499+
500+
.. _lock-store-dbal:
501+
502+
DoctrineDbalStore
503+
~~~~~~~~~~~~~~~~~
504+
505+
The DoctrineDbalStore saves locks in an SQL database. It is identical to PdoStore but requires a
506+
`Doctrine DBAL Connection`_, or a `Doctrine DBAL URL`_. This store does not
507+
support blocking, and expects a TTL to avoid stalled locks::
508+
509+
use Symfony\Component\Lock\Store\PdoStore;
510+
511+
// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
512+
$connectionOrURL = 'mysql://myuser:mypassword@127.0.0.1/app';
513+
$store = new PdoStore($connectionOrURL);
514+
515+
.. note::
516+
517+
This store does not support TTL lower than 1 second.
518+
519+
The table where values are stored is created automatically on the first call to
520+
the :method:`Symfony\\Component\\Lock\\Store\\DoctrineDbalStore::save` method.
521+
You can also add this table to your schema by calling
522+
:method:`Symfony\\Component\\Lock\\Store\\DoctrineDbalStore::configureSchema` method
523+
in your code or create this table explicitly by calling the
524+
:method:`Symfony\\Component\\Lock\\Store\\DoctrineDbalStore::createTable` method.
525+
526+
.. versionadded:: 5.4
527+
528+
The ``DoctrineDbalStore`` was introduced in Symfony 5.4 to replace ``PdoStore`` when
529+
used with Doctrine DBAL.
530+
494531
.. _lock-store-pgsql:
495532

496533
PostgreSqlStore
497534
~~~~~~~~~~~~~~~
498535

499-
The PostgreSqlStore uses `Advisory Locks`_ provided by PostgreSQL. It requires a
500-
`PDO`_ connection, a `Doctrine DBAL Connection`_, or a
501-
`Data Source Name (DSN)`_. It supports native blocking, as well as sharing
536+
The PostgreSqlStore and DoctrineDbalPostgreSqlStore uses `Advisory Locks`_ provided by PostgreSQL.
537+
It is identical to DoctrineDbalPostgreSqlStore but requires `PDO`_ connection or
538+
a `Data Source Name (DSN)`_. It supports native blocking, as well as sharing
502539
locks::
503540

504541
use Symfony\Component\Lock\Store\PostgreSqlStore;
505542

506-
// a PDO, a Doctrine DBAL connection or DSN for lazy connecting through PDO
507-
$databaseConnectionOrDSN = 'postgresql://myuser:mypassword@localhost:5634/lock';
508-
$store = new PostgreSqlStore($databaseConnectionOrDSN);
543+
// a PDO instance or DSN for lazy connecting through PDO
544+
$databaseConnectionOrDSN = 'pgsql:host=localhost;port=5634;dbname=lock';
545+
$store = new PostgreSqlStore($databaseConnectionOrDSN, ['db_username' => 'myuser', 'db_password' => 'mypassword']);
509546

510547
In opposite to the ``PdoStore``, the ``PostgreSqlStore`` does not need a table to
511548
store locks and it does not expire.
@@ -514,6 +551,34 @@ store locks and it does not expire.
514551

515552
The ``PostgreSqlStore`` was introduced in Symfony 5.2.
516553

554+
.. deprecated:: 5.4
555+
556+
Using ``PostgreSqlStore`` with Doctrine DBAL is deprecated in Symfony 5.4. Use ``DoctrineDbalPostgreSqlStore`` instead.
557+
558+
.. _lock-store-dbal-pgsql:
559+
560+
DoctrineDbalPostgreSqlStore
561+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
562+
563+
The DoctrineDbalPostgreSqlStore uses `Advisory Locks`_ provided by PostgreSQL. It is identical to PostgreSqlStore
564+
but requires a `Doctrine DBAL Connection`_ or a `Doctrine DBAL URL`_.
565+
It supports native blocking, as well as sharing
566+
locks::
567+
568+
use Symfony\Component\Lock\Store\PostgreSqlStore;
569+
570+
// a PDO instance or DSN for lazy connecting through PDO
571+
$databaseConnectionOrDSN = 'pgsql:host=localhost;port=5634;dbname=lock';
572+
$store = new PostgreSqlStore($databaseConnectionOrDSN, ['db_username' => 'myuser', 'db_password' => 'mypassword']);
573+
574+
In opposite to the ``DoctrineDbalStore``, the ``DoctrineDbalPostgreSqlStore`` does not need a table to
575+
store locks and does not expire.
576+
577+
.. versionadded:: 5.4
578+
579+
The ``DoctrineDbalPostgreSqlStore`` was introduced in Symfony 5.4 to replace ``PostgreSqlStore`` when
580+
used with Doctrine DBAL.
581+
517582
.. _lock-store-redis:
518583

519584
RedisStore
@@ -940,6 +1005,7 @@ are still running.
9401005
.. _`Advisory Locks`: https://www.postgresql.org/docs/current/explicit-locking.html
9411006
.. _`Data Source Name (DSN)`: https://en.wikipedia.org/wiki/Data_source_name
9421007
.. _`Doctrine DBAL Connection`: https://github.com/doctrine/dbal/blob/master/src/Connection.php
1008+
.. _`Doctrine DBAL URL`: https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
9431009
.. _`Expire Data from Collections by Setting TTL`: https://docs.mongodb.com/manual/tutorial/expire-data/
9441010
.. _`locks`: https://en.wikipedia.org/wiki/Lock_(computer_science)
9451011
.. _`MongoDB Connection String`: https://docs.mongodb.com/manual/reference/connection-string/

0 commit comments

Comments
 (0)
0