本文整理汇总了PHP中Predis\Client::hget方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::hget方法的具体用法?PHP Client::hget怎么用?PHP Client::hget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::hget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
public function sort($tid, Request $request)
{
$sorts = BiliBiliHelper::getSorts();
//分类非法检测
if (!array_has($sorts, $tid)) {
return $this->returnError('分类不存在');
}
$order = $request->get('order', 'hot');
$page = $request->get('page', 1);
//页码非法检测
if ($page < 1) {
$page = 1;
}
//默认取出redis
if ($order == 'hot' && $page == 1) {
$redis = new Client();
$date = $redis->hget('update', 'sort');
$sort = $redis->hget('sort', $sorts[$tid]);
$sort = json_decode($sort, true);
} else {
try {
$request_array = ['tid' => $tid, 'order' => $order, 'page' => $page, 'pagesize' => 20];
$date = date('H:i:s');
$back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array));
$sort = $back['content'];
} catch (\Exception $e) {
return $this->returnError('服务器君忙,待会再试吧...');
}
}
return view('sort')->with('content', $sort)->with('tid', $tid)->with('page', $page)->with('date', $date);
}
示例2: read
/**
* Reads a session.
*
* @param string $id A session ID
*
* @return string The session data if the session was read or created, otherwise an exception is thrown
*
* @throws \RuntimeException If the session cannot be read
*/
public function read($key, $default = null)
{
if (null !== ($data = $this->db->hget($this->getHashKey(), $key))) {
return @unserialize($data);
}
return $default;
}
示例3: get
/**
* {@inheritDoc}
*/
public function get($identifier, $type = null, $unique = null)
{
if (!is_null($type) && !is_null($unique)) {
$identifier = base64_encode(implode(':', [$identifier, $type, $unique]));
}
return $this->redis->hget('aggregator:objects', $identifier);
}
示例4: loadUserByUsername
/**
* @param string $username
* @return UserVO
* @throws UserNotFoundException
*/
public function loadUserByUsername(string $username) : UserVO
{
$userId = $this->redis->hget(UserProvider::REDIS_USER_NAMES, mb_strtolower($username));
if (empty($userId)) {
throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $username));
}
return $this->loadUserById($userId);
}
示例5: getById
/**
* @param $id
* @return DirectoryView
*/
public function getById($id) : DirectoryView
{
if (!($name = $this->client->hget($this->key, $id))) {
$model = $this->repository->getById($id);
$this->client->hset($this->key, $model->getId(), $model->getName());
return $model;
}
/** @var DirectoryView $viewClass */
$viewClass = $this->viewClass;
return $viewClass::create($id, $name);
}
示例6: htDecrField
/**
* @param string $key
* @param string $field 计数field
* @param int $step
* @param bool $zeroLimit 最小为零限制 限制最小可以自减到 0
* @return int
*/
public function htDecrField($key, $field, $step = 1, $zeroLimit = true)
{
// fix: not allow lt 0
if ($zeroLimit && (int) $this->redis->hget($key, $field) <= 0) {
return 0;
}
return $this->redis->hincrby($key, $field, -$step);
}
示例7: getAll
/**
* @return array|null
*/
public function getAll()
{
$extensionsSerialize = $this->redisClient->hgetall(self::EXTENSION_HASH_STORE);
if (!$extensionsSerialize) {
return;
}
$result = [];
foreach ($extensionsSerialize as $serialized) {
$extension = new Extension();
$extension->unserialize($serialized);
$meta = json_decode($this->redisClient->hget(self::EXTENSIONMETA_HASH_STORE, $extension->getName()), true);
$extension->setWatchers($meta['watchers']);
$extension->setStars($meta['stars']);
$result[$extension->getName()] = $extension;
}
return $result;
}
示例8: remGetCached
/**
* Get a cached value from Redis.
* @param string $id
* @param string $method
* @param array $args
* @return mixed unserialized value
*/
private static function remGetCached($key)
{
$value = self::$_redis->hget($key, 'val');
if (null !== $value && "" !== $value) {
$value = unserialize($value);
}
return $value;
}
示例9: export
/**
* @return mixed
*/
public function export()
{
if ($this->redis) {
$keys = $this->redis->hkeys($this->key);
foreach ($keys as $key) {
$v = $this->redis->hget($this->key, $key);
$v = unserialize($v);
$this->conf[$key] = $v;
}
}
return parent::export();
}
示例10: checkKeyContains
/**
* Checks whether a key contains a given item
*
* @param string $key The key
* @param mixed $item The item
* @param null $itemValue Optional and only used for zsets and hashes. If
* specified, the method will also check that the $item has this value/score
*
* @return bool
*
* @throws ModuleException
*/
private function checkKeyContains($key, $item, $itemValue = null)
{
$result = null;
if (!is_scalar($item)) {
throw new ModuleException($this, "All arguments of [dont]seeRedisKeyContains() must be scalars");
}
switch ($this->driver->type($key)) {
case 'string':
$reply = $this->driver->get($key);
$result = strpos($reply, $item) !== false;
break;
case 'list':
$reply = $this->driver->lrange($key, 0, -1);
$result = in_array($item, $reply);
break;
case 'set':
$result = $this->driver->sismember($key, $item);
break;
case 'zset':
$reply = $this->driver->zscore($key, $item);
if (is_null($reply)) {
$result = false;
} elseif (!is_null($itemValue)) {
$result = (double) $reply === (double) $itemValue;
} else {
$result = true;
}
break;
case 'hash':
$reply = $this->driver->hget($key, $item);
$result = is_null($itemValue) ? !is_null($reply) : (string) $reply === (string) $itemValue;
break;
case 'none':
throw new ModuleException($this, "Key \"{$key}\" does not exist");
break;
}
return $result;
}
示例11: usort
$messageArr = json_decode($message, true);
$messageArr['id'] = $id;
$result[] = $messageArr;
}
usort($result, function ($a, $b) {
if ($a['id'] == $b['id']) {
return 0;
}
return $a['id'] < $b['id'] ? -1 : 1;
});
$app->response->headers->set('Content-Type', 'application/json');
$app->response->setStatus(200);
echo json_encode($result);
});
$app->get('/messages/:id', function ($id) use($predis, $app) {
$data = $predis->hget(BULK_HASH, $id);
if (!$data) {
$app->response->setStatus(404);
return;
}
$result = json_decode($data, true);
$result['id'] = $id;
$app->response->headers->set('Content-Type', 'application/json');
$app->response->setStatus(200);
echo json_encode($result);
});
$app->delete('/messages/:id', function ($id) use($predis, $app) {
$data = $predis->hget(BULK_HASH, $id);
if (!$data) {
$app->response->setStatus(404);
return;
示例12: getEmailCount
/**
* @param $email
* @return int
*/
protected function getEmailCount($email)
{
$throttles = $this->redis->hget($this->key('email'), $email);
return $throttles ?: 0;
}
示例13: getRoutingDestination
/**
* @param string $commandName
* @param string $routingKey
* @return string|null
*/
public function getRoutingDestination($commandName, $routingKey)
{
return $this->client->hget(self::COMMAND_ROUTING_KEY, $this->hashCommandRouting($commandName, $routingKey));
}
示例14: findByProviderApiKey
/**
* @param string $provider
* @param string $id
*
* @return null|User
*/
public function findByProviderApiKey($provider, $key)
{
$email = $this->redisClient->hget($provider . '_API_' . self::USER_HASH_STORE, $id);
return empty($email) ? null : $this->find($email);
}
示例15: get
/**
* {@inheritdoc}
*/
public function get(string $alias) : FeatureInterface
{
return unserialize($this->redis->hget($this->prefix, $alias));
}