/** * {@inheritDoc} */ public function find(array $sources, $limit = 25, $offset = 0) { call_user_func_array([$this->redis, 'zunionstore'], array_merge([$key = sha1(microtime()), count($sources)], array_map(function ($source) { return "aggregator:sources:{$source}"; }, $sources))); $identifiers = $this->redis->zrevrange($key, $offset, $offset + $limit - 1); $this->redis->del($key); $items = $this->redis->hmget('aggregator:objects', $identifiers); foreach ($items as &$item) { $item = json_decode($item, true); $item['timestamp'] = \DateTime::createFromFormat('U', $item['timestamp']); } return $items; }
/** * 获取hash table指定的一些字段的信息 * @param $key * @param array $fields * @param bool $valToInt 将所有的值转成int,在将hash table做为计数器时有用 * @return array */ public function htGetMulti($key, array $fields, $valToInt = false) { $data = $this->redis->hmget($key, $fields); if ($data && class_exists('\\Predis\\Client') && is_subclass_of($this->redis, '\\Predis\\ClientInterface')) { $data = array_combine($fields, $data); } if ($valToInt) { array_walk($data, function (&$val) { $val = (int) $val; }); } return $data; }
/** * @param array $userIds * @return array */ public function getSessionsByUserIds(array $userIds) : array { return array_values($this->redis->hmget(RedisClientInterface::ID_SESSION_HASH, $userIds)); }