PHP code example of ar414 / redis-lock

1. Go to this page and download the library: Download ar414/redis-lock 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/ */

    

ar414 / redis-lock example snippets


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