PHP code example of wyrihaximus / react-mutex-key-prefix
1. Go to this page and download the library: Download wyrihaximus/react-mutex-key-prefix library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wyrihaximus / react-mutex-key-prefix example snippets
use WyriHaximus\React\Mutex\KeyPrefix\Mutex;
use WyriHaximus\React\Mutex\Memory;
$upstreamMutex = new Memory(); // Using Memory as example here, but can also be Redis
$mutex = new Mutex('prefix:', $upstreamMutex); // All keys are transparently prefixed with `prefix:`
$lock = $mutex->acquire('key', 1.23); // In the mutex store, the key is `prefix:key`, but in the lock we return it's just `key`, always pass the lock back to the same mutex you got it from