本文整理汇总了PHP中Predis\Client::sadd方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::sadd方法的具体用法?PHP Client::sadd怎么用?PHP Client::sadd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::sadd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToSet
public function addToSet($key, $value)
{
if (!is_array($value)) {
$value = array($value);
}
return $this->_client->sadd($key, $value);
}
示例2: createRequestToAdd
/**
* @param RequestAddInterface $addToFriendsModel
* @throws \Exception
* @return $this
*/
private function createRequestToAdd(RequestAddInterface $addToFriendsModel)
{
if ($this->isExistsRequest($addToFriendsModel->getIdRequested(), $addToFriendsModel->getIdRequester())) {
throw new \Exception('already requested', 400);
}
$key = $this->getFormattedKey($addToFriendsModel->getIdRequested());
$this->redis->sadd($key, [$addToFriendsModel->getIdRequester()]);
return $this;
}
示例3: submit
/**
* Publish a message to the queue
*
* @param \Flowpack\JobQueue\Common\Queue\Message $message
* @return void
*/
public function submit(\Flowpack\JobQueue\Common\Queue\Message $message)
{
if ($message->getIdentifier() !== NULL) {
$added = $this->client->sadd("queue:{$this->name}:ids", $message->getIdentifier());
if (!$added) {
return;
}
}
$encodedMessage = $this->encodeMessage($message);
$this->client->lpush("queue:{$this->name}:messages", $encodedMessage);
$message->setState(\Flowpack\JobQueue\Common\Queue\Message::STATE_SUBMITTED);
}
示例4: haveInRedis
/**
* Creates or modifies keys
*
* If $key already exists:
*
* - Strings: its value will be overwritten with $value
* - Other types: $value items will be appended to its value
*
* Examples:
*
* ``` php
* <?php
* // Strings: $value must be a scalar
* $I->haveInRedis('string', 'Obladi Oblada');
*
* // Lists: $value can be a scalar or an array
* $I->haveInRedis('list', ['riri', 'fifi', 'loulou']);
*
* // Sets: $value can be a scalar or an array
* $I->haveInRedis('set', ['riri', 'fifi', 'loulou']);
*
* // ZSets: $value must be an associative array with scores
* $I->haveInRedis('set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
*
* // Hashes: $value must be an associative array
* $I->haveInRedis('hash', ['obladi' => 'oblada']);
* ```
*
* @param string $type The type of the key
* @param string $key The key name
* @param mixed $value The value
*
* @throws ModuleException
*/
public function haveInRedis($type, $key, $value)
{
switch (strtolower($type)) {
case 'string':
if (!is_scalar($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "string", ' . 'third argument must be a scalar');
}
$this->driver->set($key, $value);
break;
case 'list':
$this->driver->rpush($key, $value);
break;
case 'set':
$this->driver->sadd($key, $value);
break;
case 'zset':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "zset", ' . 'third argument must be an (associative) array');
}
$this->driver->zadd($key, $value);
break;
case 'hash':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "hash", ' . 'third argument must be an array');
}
$this->driver->hmset($key, $value);
break;
default:
throw new ModuleException($this, "Unknown type \"{$type}\" for key \"{$key}\". Allowed types are " . '"string", "list", "set", "zset", "hash"');
}
}
示例5: registerKey
/**
* @param $key
*/
private function registerKey($namespace, $key)
{
if (!in_array($key, $this->registeredStates, true)) {
$namespaceKey = $this->buildNamespaceKey($namespace, $key);
$this->registeredStates[] = $namespaceKey;
$this->redis->sadd(self::STATE_MACHINE_NAMESPACE . 'registry', $namespaceKey);
}
}
示例6: register
/**
* @param $username
* @param $password
*
* @throws UsernameExistsException
*
* @return string
*/
public function register($username, $password)
{
if ($this->checkIfUsernameExists($username)) {
throw new UsernameExistsException(UsernameExistsException::MESSAGE);
}
$userId = $this->redisClient->incr("global:nextUserId");
$this->redisClient->set("username:{$username}:id", $userId);
$this->redisClient->set("uid:{$userId}:username", $username);
$this->redisClient->set("uid:{$userId}:password", $password);
$authSecret = $this->getRand();
$this->redisClient->set("uid:{$userId}:auth", $authSecret);
$this->redisClient->set("auth:{$authSecret}", $userId);
$this->redisClient->sadd("global:users", [$userId]);
$this->session->set('userId', $userId);
$this->session->set('username', $username);
return $authSecret;
}
示例7: atomicPush
/**
* Push job to redis
*
* @param string $jobId
* @param string $class
* @param array $args
* @param string $queue
* @param bool $retry
* @param float|null $doAt
* @throws exception Exception
*/
private function atomicPush($jobId, $class, $args = [], $queue = self::QUEUE, $retry = true, $doAt = null)
{
if (array_values($args) !== $args) {
throw new Exception('Associative arrays in job args are not allowed');
}
if (!is_null($doAt) && !is_float($doAt) && is_string($doAt)) {
throw new Exception('at argument needs to be in a unix epoch format. Use microtime(true).');
}
$job = $this->serializer->serialize($jobId, $class, $args, $retry);
if ($doAt === null) {
$this->redis->sadd($this->name('queues'), $queue);
$this->redis->lpush($this->name('queue', $queue), $job);
} else {
$this->redis->zadd($this->name('schedule'), [$job => $doAt]);
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
if (!is_file($file)) {
throw new \Exception(sprintf('File %s not found!', $file));
}
$db = new \PDO(sprintf('sqlite:%s', $file));
$redis = new Client(array('scheme' => 'tcp', 'host' => $input->getOption('host'), 'port' => $input->getOption('port')));
$c = 0;
foreach ($db->query("SELECT * FROM store") as $row) {
$parts = explode(':', $row['key']);
$key = sprintf('ueberDB:keys:%s', $parts[0]);
$value = sprintf('%s:%s', $parts[0], $parts[1]);
$redis->sadd($key, $value);
$redis->set($row['key'], $row['value']);
$c++;
}
if ($output->isVerbose()) {
$output->writeln(sprintf('%s values imported', $c));
}
}
示例9: addToBlacklist
/**
* @param $sid
*/
private function addToBlacklist($sid)
{
$this->redis->sadd('session:blacklist:OracleHookedRedisSessionProvider', [$sid]);
}
示例10: addToList
/**
* @inheritdoc
*/
public function addToList($list, $value)
{
return $this->predis->sadd($list, $value) > 0;
}
示例11: add
/**
* Add identifier in set
* @param $identifier
* @return int
*/
public function add($identifier)
{
return $this->redisClient->sadd($this->setName, $identifier);
}
示例12: subscribe
/**
* Adds the command to the subscription set.
*
* @param string $commandName
*/
public function subscribe($commandName)
{
$this->client->sadd(sprintf(self::COMMAND_SUBSCRIPTION_KEY, $this->hashCommandName($commandName)), [$this->nodeName]);
}
示例13: follow
/**
* @param integer $userId
*/
private function follow($userId)
{
$this->redisClient->sadd("uid:" . $userId . ":followers", [$this->sessionUserId]);
$this->redisClient->sadd("uid:" . $this->sessionUserId . ":following", [$userId]);
}
示例14: addFriendToList
/**
* @param int $userId
* @param int $userIdFriend
* @return $this;
*/
public function addFriendToList($userId, $userIdFriend)
{
$key = sprintf(self::TEMPLATE_KEY, $userId);
$this->redis->sadd($key, [$userIdFriend]);
return $this;
}
示例15: remAddIndex
private static function remAddIndex(Key $key)
{
self::$_redis->sadd($key->getPrefix(), $key->getSuffix());
self::$_redis->sadd(Key::getIndexKey(), $key->getPrefix());
}