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; } }
相关文章推荐
- awesome PHP之monolog
- PHP基础之字符串比较
- PHP数组与java数组的区别
- php框架开发yii之创建第一个应用
- YII 自动引入juquery进行表单验证
- PHPExcel
- yii 验证用户名是否存在 array("name","unique",'message'=>'用户名已经存在'),
- yii 验证确认密码是否一致 【"compare",'compareAttribute'=>'password'】
- php中 now()与date() 有什么区别
- PHP 字符串常用方法
- php解决乱码问题时,出现Cannot modify header information问题的解决方法
- php获取客户端IP
- vsftp/wordpress
- vsftp服务搭建和配置
- 全站301跳转 PHP
- matplotlib 安装
- F3-fatfree小型php框架教程(六)数据库篇
- PHP面向对象之对象串行化和反串行化
- 升级php5.5.10扩展不兼容
- PHP文件下载