本文整理汇总了PHP中Memcache::getMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::getMulti方法的具体用法?PHP Memcache::getMulti怎么用?PHP Memcache::getMulti使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::getMulti方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: groups
/**
* Returns the `group value` for each of the configured groups
* If the group initial value was not found, then it initializes
* the group accordingly.
*
* @return array
*/
public function groups() {
if (empty($this->_compiledGroupNames)) {
foreach ($this->settings['groups'] as $group) {
$this->_compiledGroupNames[] = $this->settings['prefix'] . $group;
}
}
$groups = $this->_Memcached->getMulti($this->_compiledGroupNames);
if (count($groups) !== count($this->settings['groups'])) {
foreach ($this->_compiledGroupNames as $group) {
if (!isset($groups[$group])) {
$this->_Memcached->set($group, 1, 0);
$groups[$group] = 1;
}
}
ksort($groups);
}
$result = array();
$groups = array_values($groups);
foreach ($this->settings['groups'] as $i => $group) {
$result[] = $group . $groups[$i];
}
return $result;
}
示例2: read
/**
* Read cached data
*
* @param array $keys array of keys to load
* @return array key/value cached data
*/
protected function read(array $keys)
{
$keymap = array();
$hashedkeys = array();
foreach ($keys as $key) {
$newkey = sha1($key);
$keymap[$newkey] = $key;
$hashedkeys[] = $newkey;
}
$data = false;
$cachedata = array();
if ($this->memcacheType == GitPHP_CacheResource_Memcache::Memcache) {
$cachedata = $this->memcacheObj->get($hashedkeys);
} else {
if ($this->memcacheType == GitPHP_CacheResource_Memcache::Memcached) {
$cachedata = $this->memcacheObj->getMulti($hashedkeys);
}
}
if ($cachedata) {
foreach ($cachedata as $key => $value) {
$origkey = $keymap[$key];
if (!empty($origkey)) {
$data[$origkey] = $value;
}
}
}
return $data;
}
示例3: get
/**
* 取得memcache数据,支持批量取
* @param string/array $key
* @return mixed
*/
public function get($key)
{
$this->_connect();
if (static::$_memcached_mode && \is_array($key)) {
# memcached多取
$return = $this->_memcache->getMulti($key);
} else {
$return = $this->_memcache->get($key);
}
if ($return === false) {
\Core::debug()->error($key, 'memcache mis key');
return false;
} else {
\Core::debug()->info($key, 'memcache hit key');
}
return $return;
}
示例4: get
/**
* 取得memcache数据,支持批量取
*
* @param string/array $key
* @return mixed
*/
public function get($key)
{
# 尝试连接
$this->_connect();
$is_array_key = is_array($key);
# 有前缀
if ($this->prefix) {
if ($is_array_key) {
$key_map = array();
foreach ($key as &$k) {
$key_map[$this->prefix . $k] = $k;
$k = $this->prefix . $k;
}
} else {
$key = $this->prefix . $key;
}
}
if (Cache_Driver_Memcache::$_memcached_mode && $is_array_key) {
$return = $this->_memcache->getMulti($key);
} else {
$return = $this->_memcache->get($key);
}
# 移除前缀
if ($is_array_key && $return && $this->prefix) {
$new_rs = array();
foreach ($return as $k => $item) {
$new_rs[$key_map[$k]] = $item;
}
$return = $new_rs;
}
if (false === $return) {
if (IS_DEBUG) {
Core::debug()->error($key, 'memcache mis key');
}
return false;
} else {
if (IS_DEBUG) {
Core::debug()->info($key, 'memcache hit key');
}
}
return $return;
}
示例5: get
/**
* 取得memcache数据,支持批量取
*
* @param string/array $key
* @return mixed
*/
public function get($key)
{
$this->_connect();
if (Cache_Driver_Memcache::$_memcached_mode && is_array($key)) {
# memcached多取
$return = $this->_memcache->getMulti($key);
} else {
$return = $this->_memcache->get($key);
}
if ($return === false) {
if (IS_DEBUG) {
Core::debug()->error($key, 'memcache mis key');
}
return false;
} else {
if (IS_DEBUG) {
Core::debug()->info($key, 'memcache hit key');
}
}
return $return;
}
示例6: get
/**
* Get data associated with a key.
*
* @see Memcache::get()
*
* @param mixed $keys The key or an array of keys.
*
* @return mixed The string/array on success (return type is the type of
* $keys), false on failure.
*/
public function get($keys)
{
$flags = null;
$key_map = $missing_parts = $os = $out_array = array();
$ret_array = true;
if (!is_array($keys)) {
$keys = array($keys);
$ret_array = false;
}
$search_keys = $keys;
foreach ($search_keys as $v) {
$key_map[$v] = $this->_key($v);
}
if ($this->_memcache instanceof Memcached) {
$res = $this->_memcache->getMulti(array_values($key_map));
} else {
$res = $this->_memcache->get(array_values($key_map), $flags);
}
if ($res === false) {
return false;
}
/* Check to see if we have any oversize items we need to get. */
if (!empty($this->_params['large_items'])) {
foreach ($key_map as $key => $val) {
$part_count = isset($flags[$val]) ? ($flags[$val] >> self::FLAGS_RESERVED) - 1 : -1;
switch ($part_count) {
case -1:
/* Ignore. */
unset($res[$val]);
break;
case 0:
/* Not an oversize part. */
break;
default:
$os[$key] = $this->_getOSKeyArray($key, $part_count);
foreach ($os[$key] as $val2) {
$missing_parts[] = $key_map[$val2] = $this->_key($val2);
}
break;
}
}
if (!empty($missing_parts)) {
if (($res2 = $this->_memcache->get($missing_parts)) === false) {
return false;
}
/* $res should now contain the same results as if we had
* run a single get request with all keys above. */
$res = array_merge($res, $res2);
}
}
foreach ($key_map as $k => $v) {
if (!isset($res[$v])) {
$this->_noexist[$k] = true;
}
}
foreach ($keys as $k) {
$out_array[$k] = false;
if (isset($res[$key_map[$k]])) {
$data = $res[$key_map[$k]];
if (isset($os[$k])) {
foreach ($os[$k] as $v) {
if (isset($res[$key_map[$v]])) {
$data .= $res[$key_map[$v]];
} else {
$this->delete($k);
continue 2;
}
}
}
$out_array[$k] = @unserialize($data);
} elseif (isset($os[$k]) && !isset($res[$key_map[$k]])) {
$this->delete($k);
}
}
return $ret_array ? $out_array : reset($out_array);
}