给memcache存数据
boolean Driver_Cache_Driver_Memcache::set( string/array $key [, $data $value = null , $lifetime $lifetime = integer 3600 ] )
参数列表
参数 类型 描述 默认值 $key
string/array
支持多存 $value
$data
Value 多存时此项可空 null $lifetime
$lifetime
有效期,默认3600,即1小时,0表示最大值30天(2592000) integer 3600
boolean
public function set($key, $value = null, $lifetime = 3600)
{
$this->_connect();
$is_array_key = is_array($key);
# 加前缀
if ($this->prefix)
{
if ($is_array_key)
{
$new_data = array();
foreach ($key as $k=>$v)
{
$new_data[$this->prefix . $k] = $v;
}
$key = $new_data;
unset($new_data);
}
else
{
$key = $this->prefix . $key;
}
}
if (Cache_Driver_Memcache::$_memcached_mode)
{
// memcached
if ($is_array_key)
{
$rs = $this->_memcache->setMulti($key, $lifetime);
}
else
{
$rs = $this->_memcache->set($key, $value, $lifetime);
}
}
else
{
// memcache
if ($is_array_key)
{
$rs = true;
foreach ($key as $k => $v)
{
$s = $this->_memcache->set($k, $v, $this->_get_flag($v), $lifetime);
if (false===$s)
{
$rs = false;
}
}
}
else
{
$rs = $this->_memcache->set($key, $value, $this->_get_flag($value), $lifetime);
}
}
if (IS_DEBUG)
{
if (is_array($key))
{
Core::debug()->info(array_keys($key), 'memcache set key');
}
else
{
Core::debug()->info($key, 'memcache set key');
}
}
return $rs;
}