Answer the question
In order to leave comments, you need to log in
How to work with atomic locks in Laravel?
It is necessary to use a cache in order for the work on one entity to be performed by the user who received it first, and so that it is tied to this user for a certain time.
Judging by the dock, Atomic Locks
are suitable for this,
but I don’t understand the logic of their work, can someone explain more specifically?
Answer the question
In order to leave comments, you need to log in
Well, xs is much easier than in the dock:
$product = Product::first();
$lock = Cache::lock('product_edit.' . $product->id, 10);
if ($lock->get()) {
// ту-ту-ту, я делаю что хочу
$product->name = 'flower pot';
$product->save();
// ла-ла-ла, я сделал что хотел
// дам возможность другим редактировать эту сущность заранее, зачем ждать еще 9 секунд
$lock->release();
} else {
// сорри чел, кто-то другой редагирует эту сущность
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question