您的位置:首页 > 编程语言 > PHP开发

PHP加锁解锁操作

2014-04-07 15:57 369 查看
<?php
class LockCAO extends CAO
{
private  $TP_LOCK_ACT_UID = 'lock_act_uid';
private  $TP_LOCK_ACT_SID = 'lock_act_sid';
private  $TP_LOCK_ACT_GLOBAL = 'lock_act_global';

protected function mao_config($type)
{
$maoconfig = null;
switch($type)
{
case $this->TP_LOCK_ACT_UID:
$maoconfig = array(
'xcache_enable' => false,
'xcache_expire' => 0,
'is_bin'		=> false,
'mc_key'		=> 'lock_act_uid',
);
break;
case $this->TP_LOCK_ACT_SID:
$maoconfig = array(
'xcache_enable' => false,
'xcache_expire' => 0,
'is_bin'		=> false,
'mc_key'		=> 'lock_act_sid',
);
break;
case $this->TP_LOCK_ACT_GLOBAL:
$maoconfig = array(
'xcache_enable' => false,
'xcache_expire' => 0,
'is_bin'		=> false,
'mc_key'		=> 'lock_act_global',
);
break;

}
return $maoconfig;
}
public function make_key($type,$uid=0,$sid=0)
{
$key = '';
switch ($type)
{
case $this->TP_LOCK_ACT_UID:
$key = $uid;
break;
case $this->TP_LOCK_ACT_SID:
$key = $sid;
break;
}
return $key;
}
public function addActUid($uid,$r=1)
{
$key = $this->make_key($this->TP_LOCK_ACT_UID, $uid);

$res = $this->mcadd($this->TP_LOCK_ACT_UID, $key, $r, $uid, 10);

if($res===false) return false;

return true;
}
public function getActUid($uid)
{
$key = $this->make_key($this->TP_LOCK_ACT_UID, $uid);

$res = $this->mcget($this->TP_LOCK_ACT_UID, $key, $uid);

if($res===false) return false;

return $res;
}
public function delActUid($uid)
{
$key = $this->make_key($this->TP_LOCK_ACT_UID, $uid);

$res = $this->mcdel($this->TP_LOCK_ACT_UID, $key);

if($res===false) return false;

return true;
}

public function addActSid($sid)
{
$key = $this->make_key($this->TP_LOCK_ACT_SID, "", $sid);

$res = $this->mcadd($this->TP_LOCK_ACT_SID, $key, time() , $uid, $expire_time = 10);

if($res===false) return false;

return true;
}
public function delActSid($sid)
{
$key = $this->make_key($this->TP_LOCK_ACT_SID, "", $sid);

$res = $this->mcdel($this->TP_LOCK_ACT_SID, $key);

if($res===false) return false;

return true;
}

public function addActGlobal($key,$r=1)
{
//$key = $this->make_key($this->TP_LOCK_ACT_UID, $uid, $sid);

$res = $this->mcadd($this->TP_LOCK_ACT_GLOBAL, $key, $r, $key, 10);

if($res===false) return false;

return true;
}
public function delActGlobal($key)
{
//$key = $this->make_key($this->TP_LOCK_ACT_GLOBAL, $uid, $sid);

$res = $this->mcdel($this->TP_LOCK_ACT_GLOBAL, $key);

if($res===false) return false;

return true;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: