PHP Class Cml\Lock\Base

Inheritance: implements Cml\Interfaces\Lock
Show file Open project: linhecheng/cmlphp

Protected Properties

Property Type Description
$expire integer 锁的过期时间针对Memcache/Redis两种锁有效,File锁无效 单位s 设为0时不过期。此时假如开发未手动unlock且这时出现程序挂掉的情况 __destruct未执行。这时锁必须人工介入处理 这个值可根据业务需要进行修改比如60等
$lockCache array 保存锁数据
$useCache string 锁驱动使用redis/memcache时使用的缓存

Public Methods

Method Description
__construct ( $useCache )
__destruct ( ) 定义析构函数 自动释放获得的锁
setExpire ( integer $expire = 100 ) 设置锁的过期时间
unlock ( string $key ) : void 解锁

Protected Methods

Method Description
getKey ( string $key ) : string 组装key

Method Details

__construct() public method

public __construct ( $useCache )

__destruct() public method

定义析构函数 自动释放获得的锁
public __destruct ( )

getKey() protected method

组装key
protected getKey ( string $key ) : string
$key string 要上的锁的key
return string

setExpire() public method

设置锁的过期时间
public setExpire ( integer $expire = 100 )
$expire integer

unlock() public method

解锁
public unlock ( string $key ) : void
$key string
return void

Property Details

$expire protected property

锁的过期时间针对Memcache/Redis两种锁有效,File锁无效 单位s 设为0时不过期。此时假如开发未手动unlock且这时出现程序挂掉的情况 __destruct未执行。这时锁必须人工介入处理 这个值可根据业务需要进行修改比如60等
protected int $expire
return integer

$lockCache protected property

保存锁数据
protected array $lockCache
return array

$useCache protected property

锁驱动使用redis/memcache时使用的缓存
protected string $useCache
return string