mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-23 02:45:33 +08:00
99 lines
2.5 KiB
PHP
Executable File
99 lines
2.5 KiB
PHP
Executable File
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
/**
|
||
* 导出数据存储memcache类
|
||
*
|
||
* @author kamisama.xia@gmail.com
|
||
* @version 0.1
|
||
*/
|
||
class taskmgr_cache_memcache extends taskmgr_cache_abstract implements taskmgr_cache_interface
|
||
{
|
||
|
||
static private $_cacheObj = null;
|
||
|
||
function __construct($path){
|
||
$this->connect();
|
||
}
|
||
|
||
/**
|
||
* connect
|
||
* @return mixed 返回值
|
||
*/
|
||
|
||
public function connect()
|
||
{
|
||
if(!isset(self::$_cacheObj)){
|
||
if(defined('__MEMCACHE_CONFIG') && constant('__MEMCACHE_CONFIG')){
|
||
self::$_cacheObj = new Memcache;
|
||
$config = explode(',', __MEMCACHE_CONFIG);
|
||
foreach($config AS $row){
|
||
$row = trim($row);
|
||
if(strpos($row, 'unix://') === 0){
|
||
self::$_cacheObj->addServer($row, 0);
|
||
}else{
|
||
$tmp = explode(':', $row);
|
||
self::$_cacheObj->addServer($tmp[0], $tmp[1]);
|
||
}
|
||
}
|
||
}else{
|
||
trigger_error('can\'t load __MEMCACHE_CONFIG, please check it', E_USER_ERROR);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* fetch
|
||
* @param mixed $key key
|
||
* @param mixed $result result
|
||
* @return mixed 返回值
|
||
*/
|
||
public function fetch($key, &$result)
|
||
{
|
||
$key = $this->create_key($key);
|
||
$result = self::$_cacheObj->get($key);
|
||
if($result === false){
|
||
return false;
|
||
}else{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* store
|
||
* @param mixed $key key
|
||
* @param mixed $value value
|
||
* @param mixed $ttl ttl
|
||
* @return mixed 返回值
|
||
*/
|
||
public function store($key, $value, $ttl=0)
|
||
{
|
||
$key = $this->create_key($key);
|
||
return self::$_cacheObj->set($key, $value, MEMCACHE_COMPRESSED, $ttl);
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
* @param mixed $key key
|
||
* @return mixed 返回值
|
||
*/
|
||
public function delete($key)
|
||
{
|
||
$key = $this->create_key($key);
|
||
return self::$_cacheObj->set($key, '', MEMCACHE_COMPRESSED, 1);
|
||
}
|
||
|
||
/**
|
||
* increment
|
||
* @param mixed $key key
|
||
* @param mixed $value value
|
||
* @return mixed 返回值
|
||
*/
|
||
public function increment($key, $value=1){
|
||
$key = $this->create_key($key);
|
||
return self::$_cacheObj->increment($key, $value);
|
||
}
|
||
}
|