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

Appearance settings

Commit cc06a7f

Browse filesBrowse files
committed
Fix samples
1 parent 664f50a commit cc06a7f
Copy full SHA for cc06a7f

File tree

1 file changed

+23
-12
lines changed
Filter options

1 file changed

+23
-12
lines changed

‎components/lock.rst

Copy file name to clipboardExpand all lines: components/lock.rst
+23-12Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Usage
2626
-----
2727

2828
In order to centralize state of locks, you first need to create a ``Store``.
29-
Then, you can ask to this store to create a Lock for your ``resource``.
29+
Then, you can use the :class:`Symfony\\Component\\Lock\\Factory` to create a
30+
Lock for your ``resource``.
3031

3132
The :method:`Symfony\\Component\\Lock\\LockInterface::acquire` method tries to
3233
acquire the lock. If the lock can not be acquired, the method throws a
@@ -36,11 +37,13 @@ it.
3637

3738
.. code-block:: php
3839
40+
use Symfony\Component\Lock\Factory;
3941
use Symfony\Component\Lock\Store\SemaphoreStore;
4042
use Symfony\Component\Lock\Exception\LockConflictedException;
4143
4244
$store = new SemaphoreStore();
43-
$lock = $store->createLock('invoice-pdf-generation');
45+
$factory = new Factory($store);
46+
$lock = $factory->createLock('invoice-pdf-generation');
4447
4548
try {
4649
$lock->acquire();
@@ -62,7 +65,7 @@ The first argument of ``createLock`` is a string representation of the
6265
distinguishes locks instances, even when they are created from the same
6366
``resource``.
6467
If you want to share a lock in several services. You have to share the
65-
instance of Lock returned by the ``Store::createLock`` method.
68+
instance of Lock returned by the ``Factory::createLock`` method.
6669

6770
Blocking locks
6871
--------------
@@ -77,13 +80,16 @@ you can decorate it with the ``RetryTillSaveStore``.
7780

7881
.. code-block:: php
7982
83+
use Symfony\Component\Lock\Factory;
8084
use Symfony\Component\Lock\Store\RedisStore;
8185
use Symfony\Component\Lock\Store\RetryTillSaveStore;
8286
8387
$store = new RedisStore(new \Predis\Client('tcp://localhost:6379'));
8488
$store = new RetryTillSaveStore($store);
8589
86-
$lock = $store->createLock('notification-flush');
90+
$factory = new Factory($store);
91+
92+
$lock = $factory->createLock('notification-flush');
8793
8894
$lock->acquire(true);
8995
@@ -110,17 +116,19 @@ the ``resource`` will stay lock till the timeout.
110116

111117
.. code-block:: php
112118
119+
use Symfony\Component\Lock\Factory;
113120
use Symfony\Component\Lock\Store\RedisStore;
114121
115122
$store = new RedisStore(new \Predis\Client('tcp://localhost:6379'));
116123
117-
$lock = $store->createLock('charts-generation', 30);
124+
$factory = new Factory($store);
125+
$lock = $factory->createLock('charts-generation', 30);
118126
119127
$lock->acquire();
120128
try {
121129
// perfom a job during less than 30 seconds
122130
} finally {
123-
$lock->release()
131+
$lock->release();
124132
}
125133
126134
.. tip::
@@ -136,11 +144,13 @@ regularly refresh the lock
136144

137145
.. code-block:: php
138146
147+
use Symfony\Component\Lock\Factory;
139148
use Symfony\Component\Lock\Store\RedisStore;
140149
141150
$store = new RedisStore(new \Predis\Client('tcp://localhost:6379'));
142151
143-
$lock = $store->createLock('charts-generation', 30);
152+
$factory = new Factory($store);
153+
$lock = $factory->createLock('charts-generation', 30);
144154
145155
$lock->acquire();
146156
try {
@@ -151,7 +161,7 @@ regularly refresh the lock
151161
// resource is locked for 30 more seconds.
152162
}
153163
} finally {
154-
$lock->release()
164+
$lock->release();
155165
}
156166
157167
Available Stores
@@ -219,17 +229,18 @@ The MemcachedStore stores state of ``resource`` in a Memcached server. This
219229
Memcached does not supports TTL lower than 1 seconds.
220230

221231
It requires to have installed Memcached and have created a connection that
222-
implements the ``\Memcached`` classes::
232+
implements the ``\Memcached`` class.
223233

224234
.. code-block:: php
225235
226-
use Symfony\Component\Lock\Store\RedisStore;
236+
use Symfony\Component\Lock\Store\MemcachedStore;
227237
228238
$memcached = new \Memcached();
229239
$memcached->addServer('localhost', 11211);
230240
231241
$store = new MemcachedStore($memcached);
232242
243+
233244
.. _lock-store-redis:
234245

235246
RedisStore
@@ -241,7 +252,7 @@ locks.
241252

242253
It requires to have installed Redis and have created a connection that
243254
implements the ``\Redis``, ``\RedisArray``, ``\RedisCluster`` or ``\Predis``
244-
classes::
255+
classes
245256

246257
.. code-block:: php
247258
@@ -263,7 +274,7 @@ The SemaphoreStore uses the PHP semaphore functions to lock a ``resources``.
263274
264275
use Symfony\Component\Lock\Store\SemaphoreStore;
265276
266-
$store = new SemaphoreStore($redis);
277+
$store = new SemaphoreStore();
267278
268279
.. _lock-store-combined:
269280

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.