Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteca52fc

Browse files
committed
[Lock] Add new Doctrine DBAL stores
1 parent27813fb commiteca52fc

File tree

1 file changed

+88
-21
lines changed

1 file changed

+88
-21
lines changed

‎components/lock.rst‎

Lines changed: 88 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. Itrequires 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. Itis 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 PostgreSqlStoreand DoctrineDbalPostgreSqlStoreuses `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 does not expire.
@@ -514,6 +551,35 @@ store locks and 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', 'myuser', 'mypassword');
572+
$options = ['db_username' => 'myuser', 'db_password' => 'mypassword', 'db_connection_options' => []];
573+
$store = new PostgreSqlStore($databaseConnectionOrDSN, $options);
574+
575+
In opposite to the ``DoctrineDbalStore``, the ``DoctrineDbalPostgreSqlStore`` does not need a table to
576+
store locks and does not expire.
577+
578+
..versionadded::5.4
579+
580+
The ``DoctrineDbalPostgreSqlStore`` was introduced in Symfony 5.4 to replace ``PostgreSqlStore`` when
581+
used with Doctrine DBAL.
582+
517583
.. _lock-store-redis:
518584

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp