31 lines
525 B
PHP
31 lines
525 B
PHP
<?php
|
|
namespace App\Cache\Lock;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class BaseLock
|
|
{
|
|
const TTL = 120;
|
|
|
|
function setLockNxEx($key, $value)
|
|
{
|
|
return Redis::client()->set($key, $value, 'EX', self::TTL, 'NX');
|
|
}
|
|
|
|
function setLock($key, $value = '1')
|
|
{
|
|
return Redis::client()->setex($key, self::TTL , $value);
|
|
}
|
|
|
|
function unLock($key)
|
|
{
|
|
return Redis::client()->del($key);
|
|
}
|
|
|
|
function checkLock($key)
|
|
{
|
|
return Redis::client()->get($key);
|
|
}
|
|
|
|
}
|