mirror of
https://gitee.com/ShopeX/OMS
synced 2026-04-01 13:36:45 +08:00
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
|
||
|
||
/*
|
||
* @package base
|
||
* @copyright Copyright (c) 2010, shopex. inc
|
||
* @author edwin.lzh@gmail.com
|
||
* @license
|
||
*/
|
||
class base_kvstore_mysql extends base_kvstore_abstract implements base_interface_kvstore_base
|
||
{
|
||
|
||
function __construct($prefix)
|
||
{
|
||
$this->prefix = $prefix;
|
||
}//End Function
|
||
|
||
/**
|
||
* store
|
||
* @param mixed $key key
|
||
* @param mixed $value value
|
||
* @param mixed $ttl ttl
|
||
* @return mixed 返回值
|
||
*/
|
||
public function store($key, $value, $ttl=0)
|
||
{
|
||
$rows = app::get('base')->model('kvstore')->getList('id', array('prefix'=>$this->prefix, 'key'=>$key));
|
||
$data = array('prefix'=>$this->prefix, 'key'=>$key, 'value'=>$value, 'dateline'=>time(), 'ttl'=>$ttl);
|
||
if($rows[0]['id'] > 0){
|
||
return app::get('base')->model('kvstore')->update($data, array('id'=>$rows[0]['id']));
|
||
}else{
|
||
return app::get('base')->model('kvstore')->insert($data);
|
||
}
|
||
}//End Function
|
||
|
||
/**
|
||
* fetch
|
||
* @param mixed $key key
|
||
* @param mixed $value value
|
||
* @param mixed $timeout_version timeout_version
|
||
* @return mixed 返回值
|
||
*/
|
||
public function fetch($key, &$value, $timeout_version=null)
|
||
{
|
||
$rows = kernel::database()->select(
|
||
sprintf("SELECT * FROM `sdb_base_kvstore` WHERE `prefix` = %s AND `key` = %s", kernel::database()->quote($this->prefix), kernel::database()->quote($key)),
|
||
true
|
||
);
|
||
if($rows[0]['id'] > 0 && $timeout_version < $rows[0]['dateline']){
|
||
if($rows[0]['ttl'] > 0 && ($rows[0]['dateline']+$rows[0]['ttl']) < time()){
|
||
return false;
|
||
}
|
||
$value = unserialize($rows[0]['value']);
|
||
return true;
|
||
}
|
||
return false;
|
||
}//End Function
|
||
|
||
/**
|
||
* 删除
|
||
* @param mixed $key key
|
||
* @return mixed 返回值
|
||
*/
|
||
public function delete($key)
|
||
{
|
||
return app::get('base')->model('kvstore')->delete(array('prefix'=>$this->prefix, 'key'=>$key));
|
||
}//End Function
|
||
|
||
/**
|
||
* recovery
|
||
* @param mixed $record record
|
||
* @return mixed 返回值
|
||
*/
|
||
public function recovery($record)
|
||
{
|
||
return false;
|
||
}//End Function
|
||
}//End Class
|