当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::sadd方法代码示例

本文整理汇总了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);
 }
开发者ID:Antevenio,项目名称:redis,代码行数:7,代码来源:Client.php

示例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;
 }
开发者ID:avelov,项目名称:techery_friends,代码行数:14,代码来源:RequestedFriendsService.php

示例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);
 }
开发者ID:admaykin,项目名称:Admaykin.Jobqueue.Redis,代码行数:18,代码来源:RedisQueue.php

示例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"');
     }
 }
开发者ID:solutionDrive,项目名称:Codeception,代码行数:65,代码来源:Redis.php

示例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);
     }
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:11,代码来源:StateMachine.php

示例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;
 }
开发者ID:KrunoKnego,项目名称:Symfony-Twitter-Clone,代码行数:25,代码来源:RedisRegistration.php

示例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]);
     }
 }
开发者ID:spinx,项目名称:sidekiq-job-php,代码行数:27,代码来源:Client.php

示例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));
     }
 }
开发者ID:yalamerde,项目名称:etherpad-lite-console,代码行数:21,代码来源:MigrationSqliteToRedisCommand.php

示例9: addToBlacklist

 /**
  * @param $sid
  */
 private function addToBlacklist($sid)
 {
     $this->redis->sadd('session:blacklist:OracleHookedRedisSessionProvider', [$sid]);
 }
开发者ID:akentner,项目名称:incoming-ftp,代码行数:7,代码来源:OracleHookedRedisSessionProvider.php

示例10: addToList

 /**
  * @inheritdoc
  */
 public function addToList($list, $value)
 {
     return $this->predis->sadd($list, $value) > 0;
 }
开发者ID:savritsky,项目名称:cache,代码行数:7,代码来源:PredisDriver.php

示例11: add

 /**
  * Add identifier in set
  * @param $identifier
  * @return int
  */
 public function add($identifier)
 {
     return $this->redisClient->sadd($this->setName, $identifier);
 }
开发者ID:mikicaivosevic,项目名称:online-users,代码行数:9,代码来源:RedisStorage.php

示例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]);
 }
开发者ID:fcm,项目名称:GovernorFramework,代码行数:9,代码来源:RedisTemplate.php

示例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]);
 }
开发者ID:KrunoKnego,项目名称:Symfony-Twitter-Clone,代码行数:8,代码来源:RedisFollow.php

示例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;
 }
开发者ID:avelov,项目名称:techery_friends,代码行数:11,代码来源:FriendsListsService.php

示例15: remAddIndex

 private static function remAddIndex(Key $key)
 {
     self::$_redis->sadd($key->getPrefix(), $key->getSuffix());
     self::$_redis->sadd(Key::getIndexKey(), $key->getPrefix());
 }
开发者ID:chriskite,项目名称:rem,代码行数:5,代码来源:Rem.php


注:本文中的Predis\Client::sadd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。