本文整理汇总了PHP中Memcache::setMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::setMulti方法的具体用法?PHP Memcache::setMulti怎么用?PHP Memcache::setMulti使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::setMulti方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* 给memcache存数据
*
* @param string/array $key 支持多存
* @param $data Value 多存时此项可空
* @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
* @return boolean
*/
public function set($key, $value = null, $lifetime = 3600)
{
$this->_connect();
\Core::debug()->info($key, 'memcache set key');
if (static::$_memcached_mode) {
// memcached
if (\is_array($key)) {
return $this->_memcache->setMulti($key, $lifetime);
}
return $this->_memcache->set($key, $value, $lifetime);
} else {
// memcache
if (\is_array($key)) {
$return = true;
foreach ($key as $k => $v) {
$s = $this->set($k, $v, $lifetime);
if (false === $s) {
$return = false;
}
}
return $return;
}
return $this->_memcache->set($key, $value, $this->_get_flag($value), $lifetime);
}
}
示例2: writeMany
/**
* Write many cache entries to the cache at once
*
* @param array $data An array of data to be stored in the cache
* @return array of bools for each key provided, true if the data was successfully cached, false on failure
*/
public function writeMany($data)
{
$cacheData = array();
foreach ($data as $key => $value) {
$cacheData[$this->_key($key)] = $value;
}
$success = $this->_Memcached->setMulti($cacheData);
$return = array();
foreach (array_keys($data) as $key) {
$return[$key] = $success;
}
return $return;
}
示例3: set
/**
* 给memcache存数据
*
* @param string/array $key 支持多存
* @param $data Value 多存时此项可空
* @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
* @return 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;
}
示例4: write
/**
* Write data to cache
*
* @param array $keys array of key/value data to store
* @param int $expire expiration time
* @return boolean true on success
*/
protected function write(array $keys, $expire = null)
{
if ($this->memcacheType == GitPHP_CacheResource_Memcache::Memcache) {
foreach ($keys as $key => $value) {
$this->memcacheObj->set(sha1($key), $value, 0, $expire);
}
return true;
} else {
if ($this->memcacheType == GitPHP_CacheResource_Memcache::Memcached) {
$mapped = array();
foreach ($keys as $key => $value) {
$mapped[sha1($key)] = $value;
}
$this->memcacheObj->setMulti($mapped, $expire);
return true;
}
}
return false;
}