/**
  * Set the cache for a token.
  *
  * @param $key
  * @param string $value
  * @param null $expiration
  */
 protected function cacheSet($key, $value, $expiration = null)
 {
     $this->client->set($key, $value);
     if (!empty($expiration)) {
         $this->ttl = $expiration;
     }
     $this->client->expire($key, $this->ttl);
 }
Exemple #2
0
 /**
  * @group redis-keys
  */
 public function testPreciseTtl()
 {
     $this->assertSame(-2, $this->client->ttl('foo'));
     $this->client->set('foo', 'bar');
     $this->assertSame(-1, $this->client->ttl('foo'));
     $this->client->expire('foo', 20);
     $this->assertThat($this->client->pttl('foo'), $this->logicalAnd($this->greaterThan(0), $this->lessThanOrEqual(20000)));
 }
 /**
  * @inheritdoc
  */
 public function registerNonceAndTimestamp($nonce, $timestamp, ConsumerInterface $consumer)
 {
     if ($this->checkNonceAndTimestampUnicity($nonce, $timestamp, $consumer)) {
         $noncesRedisKey = $this->noncesRedisKey($consumer, $timestamp);
         $this->client->sadd($noncesRedisKey, [$nonce]);
         $this->client->expire($noncesRedisKey, $this->ttl);
         $timestampsKey = $this->timestampsKey($consumer);
         $this->client->zadd($timestampsKey, $timestamp, $timestamp);
         // While we're here, only keep the top 10 items.
         $sortedSet = $this->client->zrevrange($timestampsKey, 0, -1);
         if (is_array($sortedSet) && !empty($sortedSet)) {
             $lastTimestamp = $sortedSet[0];
             $this->client->zremrangebyscore($timestampsKey, 0, $lastTimestamp - 1);
         }
         return true;
     } else {
         return false;
     }
 }
 /**
  * @param SessionInterface $session
  * @param Response $response
  */
 private function postRequestHandle(SessionInterface $session, Response $response)
 {
     if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig())) {
         $id = $session->getId();
         $key = 'session:' . $id;
         $content = $session->all();
         unset($content['_token'], $content['flash']);
         $lastSeen = time();
         $content['last_seen'] = $lastSeen;
         $session->set('last_seen', $lastSeen);
         $value = Json::dump($content);
         $this->redis->watch($key);
         $this->redis->multi();
         $this->redis->set($key, $value);
         $this->redis->expire($key, $this->getSessionLifetimeInSeconds());
         $this->redis->exec();
         $cookie = new Cookie($this->key, $id, $this->getCookieExpirationDate(), $config['path'], $config['domain'], Arr::get($config, 'secure', false));
         $response->headers->setCookie($cookie);
     }
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function updateTimestamp($sessionId, $data)
 {
     $this->redis->expire($sessionId, $this->ttl);
 }
Exemple #6
0
 /**
  * {@inheritDoc}
  */
 public function expire($key, $ttl)
 {
     return $this->predis->expire($key, $ttl);
 }