Example #1
0
 public function addToSet($key, $value)
 {
     if (!is_array($value)) {
         $value = array($value);
     }
     return $this->_client->sadd($key, $value);
 }
 /**
  * @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;
 }
 /**
  * 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);
 }
Example #4
0
 /**
  * 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"');
     }
 }
Example #5
0
 /**
  * @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);
     }
 }
 /**
  * @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;
 }
Example #7
0
 /**
  * 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]);
     }
 }
 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));
     }
 }
 /**
  * @param $sid
  */
 private function addToBlacklist($sid)
 {
     $this->redis->sadd('session:blacklist:OracleHookedRedisSessionProvider', [$sid]);
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function addToList($list, $value)
 {
     return $this->predis->sadd($list, $value) > 0;
 }
 /**
  * Add identifier in set
  * @param $identifier
  * @return int
  */
 public function add($identifier)
 {
     return $this->redisClient->sadd($this->setName, $identifier);
 }
Example #12
0
 /**
  * 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]);
 }
 /**
  * @param integer $userId
  */
 private function follow($userId)
 {
     $this->redisClient->sadd("uid:" . $userId . ":followers", [$this->sessionUserId]);
     $this->redisClient->sadd("uid:" . $this->sessionUserId . ":following", [$userId]);
 }
 /**
  * @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;
 }
Example #15
0
 private static function remAddIndex(Key $key)
 {
     self::$_redis->sadd($key->getPrefix(), $key->getSuffix());
     self::$_redis->sadd(Key::getIndexKey(), $key->getPrefix());
 }