本文整理汇总了PHP中Memcached::getMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::getMulti方法的具体用法?PHP Memcached::getMulti怎么用?PHP Memcached::getMulti使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::getMulti方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: multiGet
/**
* @param string[] $keys
* @return mixed[]
*/
public function multiGet(string ...$keys) : array
{
if (count($keys) === 0) {
return [];
}
return $this->client->getMulti($keys);
}
开发者ID:lizards-and-pumpkins,项目名称:lib-key-value-store-memcached,代码行数:11,代码来源:MemcachedKeyValueStore.php
示例2: getMulti
/**
* {@inheritdoc}
*/
public function getMulti(array $keys, array &$tokens = null)
{
$return = $this->client->getMulti($keys, $tokens);
// HHVMs getMulti() returns null instead of empty array for no results,
// so normalize that
$tokens = $tokens ?: array();
return $return ?: array();
}
示例3: getArrayDataFromStorage
/**
* {@inheritdoc}
*/
protected function getArrayDataFromStorage(array $keys)
{
$result = $this->memcached->getMulti($keys);
if ($result === false) {
return [];
}
return $result;
}
示例4: multiRead
public function multiRead($keys)
{
$cas = null;
$values = $this->store->getMulti($keys, $cas, Memcached::GET_PRESERVE_ORDER);
if (!$values) {
$values = array_fill_keys($keys, null);
}
return $values;
}
示例5: read
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
$_keys = $lookup = [];
list($_keys, $lookup) = $this->eachKeys($keys, $_keys, $lookup);
$_res = [];
$res = $this->memcached->getMulti($_keys);
foreach ($res as $k => $v) {
$_res[$lookup[$k]] = $v;
}
return $_res;
}
示例6: many
/**
* Retrieve multiple items from the cache by key.
*
* Items not found in the cache will have a null value.
*
* @param array $keys
* @return array
*/
public function many(array $keys)
{
$prefixedKeys = array_map(function ($key) {
return $this->prefix . $key;
}, $keys);
$values = $this->memcached->getMulti($prefixedKeys, null, Memcached::GET_PRESERVE_ORDER);
if ($this->memcached->getResultCode() != 0) {
return array_fill_keys($keys, null);
}
return array_combine($keys, $values);
}
示例7: getMulti
/**
* {@inheritdoc}
*/
public function getMulti(array $keys, array &$tokens = null)
{
$keys = array_map(array($this, 'encodeKey'), $keys);
$return = $this->client->getMulti($keys, $tokens);
$keys = array_map(array($this, 'decodeKey'), array_keys($return));
$return = array_combine($keys, $return);
// HHVMs getMulti() returns null instead of empty array for no results,
// so normalize that
$tokens = $tokens ?: array();
$tokens = array_combine($keys, $tokens);
return $return ?: array();
}
示例8: getMulti
/**
* 获取多条数据记录
* @param array $keys
* @return mixed
*/
public function getMulti(array $keys)
{
//保证返回的key的顺序和请求时一致
$data = $this->dbh->getMulti($keys, $cas, \Memcached::GET_PRESERVE_ORDER);
if ($data === false) {
if ($this->dbh->getResultCode() == \Memcached::RES_NOTFOUND) {
return array();
} else {
$this->error('getMulti', json_encode($keys));
}
}
return $data;
}
示例9: mget
/**
* Get multiple values from the cache.
*
* @param array $keys An array of keys to get
*
* @return array An array of JSON objects
*/
public function mget(array $keys = array())
{
$values = $this->client->getMulti($keys);
$rtn = [];
// The Memcached extension returns false not null for nonexistent
// values. For consistency's sake, we spoof that here
foreach ($keys as $key) {
if (!isset($values[$key]) || $values[$key] === false) {
$values[$key] = null;
}
$rtn[$this->instance->unkey($key)] = $values[$key];
}
return $rtn;
}
示例10: getMulti
public function getMulti($keys)
{
$result = new MultiGetResult($keys);
$null = null;
$cached = $this->memcached->getMulti(array_keys($keys), $null, \Memcached::GET_PRESERVE_ORDER);
foreach ($cached as $key => $value) {
if (null === $value) {
$id = $keys[$key];
$result->miss($id, $key);
} else {
$result->hit($key, $value);
}
}
return $result;
}
示例11: getItems
/**
* Get multiple items.
*
* Options:
* - ttl <float> optional
* - The time-to-life (Default: ttl of object)
* - namespace <string> optional
* - The namespace to use (Default: namespace of object)
*
* @param array $keys
* @param array $options
* @return array Assoziative array of existing keys and values or false on failure
* @throws Exception
*
* @triggers getItems.pre(PreEvent)
* @triggers getItems.post(PostEvent)
* @triggers getItems.exception(ExceptionEvent)
*/
public function getItems(array $keys, array $options = array())
{
$baseOptions = $this->getOptions();
if (!$baseOptions->getReadable()) {
return array();
}
$this->normalizeOptions($options);
$args = new ArrayObject(array('keys' => &$keys, 'options' => &$options));
try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}
$namespaceSep = $baseOptions->getNamespaceSeparator();
$internalKeys = array();
foreach ($keys as $key) {
$internalKeys[] = $options['namespace'] . $namespaceSep . $key;
}
$fetch = $this->memcached->getMulti($internalKeys);
if ($fetch === false) {
throw new Exception\ItemNotFoundException('Memcached::getMulti(<array>) failed');
}
// remove namespace prefix
$prefixL = strlen($options['namespace'] . $namespaceSep);
$result = array();
foreach ($fetch as $internalKey => &$value) {
$result[substr($internalKey, $prefixL)] = $value;
}
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
}
}
示例12: get
/**
* @Name get 根据键名获取值
*
* @param string $key key
* @return array OR json object OR string...
* add by cheng.yafei
*
*/
public function get($key = NULL)
{
if ($this->m) {
$keyName = $this->key_name($key);
if (isset($this->local_cache[$keyName])) {
return $this->local_cache[$keyName];
}
if (is_null($key)) {
$this->errors[] = 'The key value cannot be NULL';
return false;
}
if (is_array($key)) {
foreach ($key as $n => $k) {
$key[$n] = $this->key_name($k);
}
return $this->m->getMulti($key);
} else {
$obj = $this->m->get($keyName);
$this->local_cache[$keyName] = $obj;
return $obj;
}
} else {
return false;
}
}
示例13: 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;
}
示例14: getCounters
public function getCounters()
{
$counters = array();
$result = $this->memcache->getMulti(array($this->prefix . 'hit', $this->prefix . 'miss', $this->prefix . 'error'));
$counters['hit'] = array_key_exists($this->prefix . 'hit', $result) ? $result[$this->prefix . 'hit'] : 0;
$counters['miss'] = array_key_exists($this->prefix . 'miss', $result) ? $result[$this->prefix . 'miss'] : 0;
$counters['error'] = array_key_exists($this->prefix . 'error', $result) ? $result[$this->prefix . 'error'] : 0;
$counters['age'] = $this->getReportAge();
return $counters;
}
示例15: internalGetMetadatas
/**
* Get metadata of multiple items
*
* Options:
* - namespace <string> optional
* - The namespace to use
*
* @param array $normalizedKeys
* @param array $normalizedOptions
* @return array
* @throws Exception\ExceptionInterface
*
* @triggers getMetadatas.pre(PreEvent)
* @triggers getMetadatas.post(PostEvent)
* @triggers getMetadatas.exception(ExceptionEvent)
*/
protected function internalGetMetadatas(array &$normalizedKeys, array &$normalizedOptions)
{
$this->memcached->setOption(MemcachedResource::OPT_PREFIX_KEY, $normalizedOptions['namespace']);
$result = $this->memcached->getMulti($normalizedKeys);
if ($result === false) {
throw $this->getExceptionByResultCode($this->memcached->getResultCode());
}
foreach ($result as $key => &$value) {
$value = array();
}
return $result;
}