Exemplo n.º 1
0
 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);
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * {@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);
 }
Exemplo n.º 4
0
 /**
  * @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);
 }
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
 /**
  * @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);
 }
Exemplo n.º 7
0
 /**
  * @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;
 }
Exemplo n.º 8
0
 /**
  * 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;
 }
Exemplo n.º 9
0
 /**
  * @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();
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
Exemplo n.º 11
0
        $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;
Exemplo n.º 12
0
 /**
  * @param $email
  * @return int
  */
 protected function getEmailCount($email)
 {
     $throttles = $this->redis->hget($this->key('email'), $email);
     return $throttles ?: 0;
 }
Exemplo n.º 13
0
 /**
  * @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));
 }
Exemplo n.º 14
0
 /**
  * @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);
 }
Exemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function get(string $alias) : FeatureInterface
 {
     return unserialize($this->redis->hget($this->prefix, $alias));
 }