PHP use Redis Pessimistic Lock uses redis keys: setnx, get, getset, del
composer require ar414/redis-lock
use Ar414\RedisLock;
$redis = new \Redis();
$redis->connect('127.0.0.1','6379');
$lockTimeOut = 5;
$redisLock = new RedisLock($redis,$lockTimeOut);
$lockKey = 'lock:user:wallet:uid:1001';
$lockExpire = $redisLock->getLock($lockKey);
if(!$lockExpire || $lockExpire < time()){
throw new \Exception('Busy Lock');
}
//TODO:Business logic
$redisLock->releaseLock($lockKey,$lockExpire);