本文整理汇总了PHP中Predis\Client::mget方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::mget方法的具体用法?PHP Client::mget怎么用?PHP Client::mget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::mget方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTextsByUser
/**
* @param $hostUid
* @param $key
* @return null|UserText
*/
public function getTextsByUser($hostUid, $cached = true)
{
if ($cached) {
$pattern = $this->buildKey($hostUid, '*', '*');
$prefix = $this->redis->getOptions()->prefix;
$redisKeys = array_map(function ($redisKey) use($prefix) {
if (substr($redisKey, 0, strlen($prefix)) == $prefix) {
$redisKey = substr($redisKey, strlen($prefix));
}
return $redisKey;
}, $this->redis->keys($pattern));
if (count($redisKeys) > 0) {
$result = array_combine($redisKeys, $this->redis->mget($redisKeys));
foreach ($result as $redisKey => $text) {
list(, , $userId, , $key, $lang) = explode(':', $redisKey);
$this->texts[$userId][$key][$lang] = $text;
}
}
}
if (!$cached || !isset($this->texts[$hostUid]) || !$this->texts[$hostUid]) {
$this->texts[$hostUid] = $this->getTextsByHostFromMysql($hostUid);
$mset = [];
foreach ($this->texts[$hostUid] as $key => $langs) {
foreach ($langs as $lang => $text) {
$mset[$this->buildKey($hostUid, $key, $lang)] = $text;
}
}
if ($mset) {
$this->redis->mset($mset);
}
}
return $this->texts[$hostUid];
}
示例2: getMany
/**
* Retrieves many item from the cache.
*
* @param array $keys
*
* @return mixed
*/
public function getMany(array $keys) : array
{
// Retrieve all keys
$items = $this->predis->mget(array_map(function ($key) {
return $this->prefix . $key;
}, $keys));
// Unserialize items
return array_map(function ($item) {
return is_numeric($item) ? $item : unserialize($item);
}, $items);
}
示例3: 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->mget($keys);
$rtn = [];
// The Redis extension returns false not null for nonexistent
// values. For consistency's sake, we spoof that here
foreach ($keys as $index => $key) {
$value = $values[$index];
$rtn[$this->instance->unkey($key)] = $value;
}
return $rtn;
}
示例4: get
public function get($keys)
{
if (!$keys) {
return [];
}
$keyValue = array_combine($keys, $this->redis->mget($keys));
array_walk($keyValue, function (&$item) {
$item = json_decode($item);
});
$keyValue = array_filter($keyValue, function ($value) {
return !is_null($value);
});
return $keyValue;
}
示例5: getStatusQueue
function getStatusQueue()
{
//$iterator = new Iterator\Keyspace($this->redisClient, $this->taskListKey . "*", 2000);
$iterator = new Iterator\Keyspace($this->redisClient, "*", 2000);
//$iterator = new Iterator\Keyspace($this->redisClient, $this->statusKey . "*", 2000);
$keys = [];
foreach ($iterator as $key) {
$keys[] = $key;
}
if (!count($keys)) {
return [];
}
$values = $this->redisClient->mget($keys);
return array_combine($keys, $values);
}
示例6: multiRead
public function multiRead($keys)
{
if ($prefix = $this->prefix) {
$prefixed = array_map(function ($v) use($prefix) {
return $prefix . $v;
}, $keys);
} else {
$prefixed = $keys;
}
$values = $this->store->mget($prefixed);
foreach ($values as &$v) {
if ($v !== null) {
$v = unserialize($v);
}
}
return array_combine($keys, $values);
}
示例7: getStates
/**
* @param string $namespace
* @param array $keys
*
* @return array
*/
public function getStates($namespace, array $keys)
{
$values = [];
$namespaceKeys = array_map(function ($key) use($namespace) {
return $this->buildCurrentKey($this->buildNamespaceKey($namespace, $key));
}, $keys);
if (count($namespaceKeys) > 0) {
$values = array_combine($keys, $this->redis->mget($namespaceKeys));
}
return $values;
}
示例8: getQueueEntries
private function getQueueEntries($keyStub)
{
$iterator = new Iterator\Keyspace($this->redisClient, $keyStub . "*", 2000);
$keyList = [];
foreach ($iterator as $key) {
$keyList[] = $key;
}
if (!count($keyList)) {
return [];
}
$values = $this->redisClient->mget($keyList);
return array_combine($keyList, $values);
}
示例9: getUsersFromRedis
/**
* @param $namespace
* @param array $uids
*/
protected function getUsersFromRedis($namespace, array $uids = [])
{
$users = [];
$keys = array_map(function ($uid) use($namespace) {
return 'users:' . $namespace . ':' . $uid;
}, $uids);
if (count($keys) > 0) {
$data = $this->redis->mget($keys);
foreach ($data as $serializedUserModel) {
/** @var $userModel Model\User */
if ($serializedUserModel) {
$userModel = unserialize($serializedUserModel);
$users[$userModel->getUid()] = $userModel;
}
}
}
return $users;
}
示例10: read
/**
* {@inheritdoc}
*/
protected function read(array $keys)
{
$values = $this->client->mget($keys);
return array_combine($keys, $values);
}