Example #1
0
 /**
  * @param string $sessionId
  * @return boolean
  */
 public function hasSession($sessionId)
 {
     if ($this->redis->exists('session_' . $sessionId)) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Get a variable
  *
  * @param string $key
  * @param mixed  $default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if ($this->client->exists($this->namespace . $key)) {
         return $this->client->get($this->namespace . $key);
     } else {
         return $default;
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getUpdatedAt()
 {
     if ($this->client->exists('migraine:date')) {
         $date = new \DateTime();
         $date->setTimestamp(intval($this->client->get('migraine:date')));
         return $date;
     }
     return null;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function isCached($providerName, $query)
 {
     if (!$this->redis->exists($key = $this->getKey($providerName, $query))) {
         return false;
     }
     $cached = new BatchGeocoded();
     $cached->fromArray($this->deserialize($this->redis->get($key)));
     return $cached;
 }
 /**
  * Checks if the activation key is present in the redis database.
  *
  * @param string $activationKey
  *
  * @return bool
  */
 private function lookupKeyInRedisDatabase($activationKey)
 {
     $persistentKey = $this->generateRedisKeyByApprovalKey($activationKey);
     $exists = $this->redis->exists($persistentKey);
     // the key is not needed anymore because the approval validation will be triggered once only.
     if ($exists) {
         $this->redis->del($persistentKey);
     }
     return $exists;
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function getAvailability(\string $id) : \bool
 {
     $key = sprintf(self::QUANTITY_KEY, $id);
     if (!$this->predis->exists($key)) {
         $value = $this->repository->getAvailability($id);
         $this->saveAvailability($id, $value);
     } else {
         $value = (int) $this->predis->get($key);
     }
     return $value;
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function getById(\string $id) : CustomerView
 {
     $key = self::KEY . ':' . $id;
     if ($this->client->exists($key)) {
         $item = $this->client->hgetall($key);
         $model = $this->createViewModel($item);
     } else {
         $model = $this->repository->getById($id);
         $this->save($model);
     }
     return $model;
 }
 /**
  * @inheritDoc
  */
 public function getAllIndexed() : array
 {
     if (!$this->client->exists($this->key)) {
         $data = $this->repository->getAllIndexed();
         if ($data) {
             $this->client->hmset($this->key, $data);
         }
     } else {
         $data = $this->client->hgetall($this->key);
     }
     return $data;
 }
 public function getEventsFor($id)
 {
     if (!$this->predis->exists('events:' . $id)) {
         throw new AggregateDoesNotExist($id);
     }
     $serializedEvents = $this->predis->lrange('events:' . $id, 0, -1);
     $eventStream = [];
     foreach ($serializedEvents as $serializedEvent) {
         $eventData = $this->serializer->deserialize($serializedEvent, 'array', 'json');
         $eventStream[] = $this->serializer->deserialize($eventData['data'], $eventData['type'], 'json');
     }
     return new EventStream($id, $eventStream);
 }
 /**
  * @param EventInterface $event
  */
 public function handle(EventInterface $event)
 {
     $this->redis->lpush(self::BUFFER_LIST_KEY, json_encode($event->toArray()));
     if ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
         $this->redis->pexpire(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS);
     } else {
         $this->redis->psetex(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS, '1');
         while ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
             usleep(self::BUFFER_SLEEP_MILLISECONDS);
         }
         $this->handleBufferedEvents();
     }
 }
 protected function getFromCache($key)
 {
     if (!$this->cache->exists($key)) {
         return null;
     }
     return unserialize($this->cache->get($key));
 }
Example #12
0
 /**
  * @param string $digest
  * @param string $nonce
  * @param string $created
  * @param string $secret
  *
  * @return bool
  * @throws \Symfony\Component\Security\Core\Exception\NonceExpiredException
  */
 protected function validateDigest($digest, $nonce, $created, $secret)
 {
     /*
      * закомментили 7.01.2014 из-за проблемы возможного расхождения с клиентским временем
      *
     // Check created time is not in the future
     if (strtotime($created) > time()) {
         return false;
     }
     
     // Expire timestamp after 5 minutes
     if (time() - strtotime($created) > self::TTL) {
         return false;
     }
     */
     // Validate nonce is unique within 5 minutes
     if ($this->redis->exists(self::PREFIX . ':' . $nonce)) {
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Previously used nonce detected: %s', base64_decode($nonce)));
         }
         throw new NonceExpiredException('Previously used nonce detected');
     }
     $this->redis->setex(self::PREFIX . ':' . $nonce, self::TTL, time());
     // Validate Secret
     $expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('[+] %s, [=] %s (created: %s, nonce: %s, secret: %s)', $digest, $expected, $created, base64_decode($nonce), $secret));
     }
     return $digest === $expected;
 }
 /**
  * Appends data to an existing item on the Redis server.
  *
  * @param  string $key
  * @param  string $value
  * @param  int    $expiration
  * @return bool
  */
 protected function appendValue($key, $value, $expiration = 0)
 {
     if ($this->redis->exists($key)) {
         $this->redis->append($key, $value);
         return $this->redis->expire($key, $expiration);
     }
     return $this->redis->setex($key, $expiration, $value);
 }
Example #14
0
 /**
  * @covers BehEh\Flaps\Storage\PredisStorage::expireIn
  */
 public function testExpireIn()
 {
     $this->assertEquals(0, $this->client->exists('key'));
     $this->assertEquals(0, $this->client->exists('key:timestamp'));
     $this->storage->setValue('key', 1);
     $this->storage->setTimestamp('key', 1425829426.0);
     $this->assertEquals(1, $this->client->exists('key'));
     $this->assertEquals(1, $this->client->exists('key:timestamp'));
     $this->assertEquals(1, $this->storage->expireIn('key', 0));
     $this->assertEquals(0, $this->client->exists('key'));
     $this->assertEquals(0, $this->client->exists('key:timestamp'));
     $this->assertEquals(0, $this->storage->expireIn('key', 0));
 }
Example #15
0
 /**
  * {@inheritdoc}
  * Example:
  * <code>
  * //Does Andres have access to the customers resource to create?
  * $acl->isAllowed('Andres', 'Products', 'create');
  * //Do guests have access to any resource to edit?
  * $acl->isAllowed('guests', '*', 'edit');
  * </code>
  *
  * @param string $role
  * @param string $resource
  * @param string $access
  *
  * @return bool
  */
 public function isAllowed($role, $resource, $access)
 {
     if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
         return Acl::ALLOW;
     }
     if ($this->redis->exists("rolesInherits:{$role}")) {
         $rolesInherits = $this->redis->sMembers("rolesInherits:{$role}");
         foreach ($rolesInherits as $role) {
             if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
                 return Acl::ALLOW;
             }
         }
     }
     /**
      * Return the default access action
      */
     return $this->getDefaultAction();
 }
Example #16
0
 /**
  *
  */
 public function flush()
 {
     $this->client->transaction(function () {
         foreach ($this->buffer as $name => $options) {
             $ttl = $this->client->ttl($name);
             $exists = $this->client->exists($name);
             $this->client->set($name, $options['value']);
             if ($options['expire'] > 0) {
                 $this->client->expire($name, $options['expire']);
             }
             if ($options['expire'] < 0) {
                 if (!$exists || $ttl < 0) {
                     $this->client->expireat($name, time() + $options['expire'] * -1);
                 } else {
                     $this->client->expire($name, $ttl);
                 }
             }
         }
     });
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function contains($id)
 {
     return $this->client->exists($this->prefix . $id);
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 protected function doContains($id)
 {
     return (bool) $this->redis->exists($id);
 }
Example #19
0
 /**
  * Checks if a key-value pair exists.
  *
  * @param string $key Cache key.
  *
  * @return boolean
  */
 public function exists($key)
 {
     return $this->redisClient->exists($key);
 }
Example #20
0
 public function exists($key)
 {
     $this->load();
     return $this->client->exists($key);
 }
Example #21
0
 /**
  * redis 中 key 是否存在
  * @param string $key
  * @return bool
  */
 public function existsKey($key)
 {
     return (bool) $this->redis->exists($key);
 }
 /**
  * Checks if an item exists in the cache.
  *
  * @param string $key
  *
  * @return bool
  */
 public function exists(string $key) : bool
 {
     return (bool) $this->predis->exists($this->prefix . $key);
 }
Example #23
0
 /**
  * @inheritdoc
  */
 public function has($key)
 {
     return $this->predis->exists($key);
 }
 /**
  * {@inheritdoc}
  */
 public function isAccountTemporaryBlocked(string $user) : bool
 {
     return (bool) $this->client->exists($this->buildStorageKeyWithID($user));
 }
Example #25
0
 public function exists($id)
 {
     return $this->redis->exists($id);
 }
Example #26
0
 /**
  * ### Checks if the key/value pair exists
  *
  * @param string $key
  * @return int
  */
 public function exists($key)
 {
     return $this->conn->exists($key);
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 protected function doContains($id)
 {
     return $this->client->exists($id);
 }
 /**
  * Test if the Lockable can be locked.
  *
  * @param LockableInterface $lockable
  * @return boolean
  */
 public function canLock(LockableInterface $lockable)
 {
     return !$this->client->exists($lockable->getLockName());
 }
 /**
  * {@inheritdoc}
  */
 public function contains($id)
 {
     return (bool) $this->_redis->exists($this->_getNamespacedId($id));
 }
Example #30
0
 /**
  * @param ResourceEntityInterface $entity
  * @return boolean
  */
 protected function hasResourceForEntity(ResourceEntityInterface $entity)
 {
     $key = $this->getKeyFromEntity($entity);
     return $this->redis->exists($key);
 }