laravel implemented using a distributed lock redis - may be used to prevent duplicate form submission

Manage cross-process locks:

Here are just a personal understanding, if in doubt please refer to the official documentation   https://xueyuanjun.com/post/19506.html#bkmrk-%E5%8E%9F%E5%AD%90%E9%94%81

. $ key = 'Test:' $ UID; 
// in the controller, to lock the key 10 seconds, if not actively released, after 10 seconds, the server will automatically release
$ lock = Cache :: lock ($ key , 10);
$ Result = $ lock -> GET ();
IF ($ Result) {
// simulate complex calculations, then the code is not executed, and the next request coming
SLEEP (2);
echo 'performed a form submission! ';
// initiative to release the lock
Cache :: Lock ($ Key) -> forceRelease ();
}
echo' Please do not repeat frequently submit the form ';

Guess you like

Origin www.cnblogs.com/oujianjun/p/11865346.html