/** * */ private function updateValues() { $this->registeredStates = $this->redis->smembers(self::STATE_MACHINE_NAMESPACE . 'registry'); if (count($this->registeredStates) > 0) { $currentValueRedisKeys = array_map([$this, 'buildCurrentKey'], $this->registeredStates); $previousValueRedisKeys = array_map([$this, 'buildPreviousKey'], $this->registeredStates); list($currentValues, $previousValues) = $this->redis->pipeline(function (Pipeline $pipe) use($currentValueRedisKeys, $previousValueRedisKeys) { $pipe->mget($currentValueRedisKeys); $pipe->mget($previousValueRedisKeys); }); $this->currentValues = array_combine($this->registeredStates, $currentValues); $this->previousValues = array_combine($this->registeredStates, $previousValues); } }
/** * @param string $status */ public function tweet($status) { $postId = $this->redisClient->incr("global:nextPostId"); $userId = $this->session->get('userId'); $post = $userId . "|" . (new \DateTime())->format('d/m/y') . "|" . $status; $this->redisClient->set("post:{$postId}", $post); $followers = $this->redisClient->smembers("uid:" . $userId . ":followers"); if ($followers === false) { $followers = []; } $followers[] = $userId; foreach ($followers as $fid) { $this->redisClient->lpush("uid:{$fid}:posts", [$postId]); } $this->redisClient->lpush("global:timeline", [$postId]); $this->redisClient->ltrim("global:timeline", 0, 1000); }
private static function remAllKeys() { $keys = array(); $prefix_key = Key::getIndexKey(); $prefixes = self::$_redis->smembers($prefix_key); foreach ($prefixes as $prefix) { $suffixes = self::$_redis->smembers($prefix); foreach ($suffixes as $suffix) { $keys[] = Key::fromString($prefix . ":" . $suffix); } } return $keys; }
/** * Checks whether a key exists and, optionally, whether it has a given $value * * @param string $key The key name * @param mixed $value Optional. If specified, also checks the key has this * value. Booleans will be converted to 1 and 0 (even inside arrays) * * @return bool */ private function checkKeyExists($key, $value = null) { $type = $this->driver->type($key); if (is_null($value)) { return $type != 'none'; } $value = $this->boolToString($value); switch ($type) { case 'string': $reply = $this->driver->get($key); // Allow non strict equality (2 equals '2') $result = $reply == $value; break; case 'list': $reply = $this->driver->lrange($key, 0, -1); // Check both arrays have the same key/value pairs + same order $result = $reply === $value; break; case 'set': $reply = $this->driver->smembers($key); // Only check both arrays have the same values sort($reply); sort($value); $result = $reply === $value; break; case 'zset': $reply = $this->driver->zrange($key, 0, -1, 'WITHSCORES'); // Check both arrays have the same key/value pairs + same order $reply = $this->scoresToFloat($reply); $value = $this->scoresToFloat($value); $result = $reply === $value; break; case 'hash': $reply = $this->driver->hgetall($key); // Only check both arrays have the same key/value pairs (==) $result = $reply == $value; break; default: $result = false; } return $result; }
/** * @inheritdoc */ public function getList($listName) { return $this->predis->smembers($listName); }
/** * Return all identifiers from set * @return array */ public function getOnlineUsers() { return $this->redisClient->smembers($this->setName); }
/** * @param string $commandName * @return array */ public function getSubscriptions($commandName) { return $this->client->smembers(sprintf(self::COMMAND_SUBSCRIPTION_KEY, $this->hashCommandName($commandName))); }
/** * Запрос id всех игроков онлайн из redis * @return int[] */ public function getOnlineUsersIds() : array { return $this->redis->smembers(RedisClientInterface::ONLINE_LIST); }
/** * @param int $userId * @return array */ public function getSimpleFriendsList($userId) { $key = sprintf(self::TEMPLATE_KEY, $userId); return $this->redis->smembers($key); }
/** * 获取集合的全部数据 * @param $key * @return array */ public function getSet($key) { return $this->redis->smembers($key); }
/** * @param int $userId * @return array */ public function getListOfRequester($userId) { $key = sprintf(self::TEMPLATE_ADD_REQUEST, $userId); return $this->redis->smembers($key); }