Пример #1
0
 /**
  * Releases the lock, if it has not been released already
  */
 public function release()
 {
     if ($this->released) {
         return;
     }
     // Only release the lock if it hasn't expired
     if ($this->expire >= time()) {
         $this->redis->del($this->key);
     }
     $this->released = true;
 }
Пример #2
0
 /**
  * Remove an ID from an index
  * @param  string $id
  * @param  string $index
  * @return void
  */
 protected function removeIndexId(string $id, string $index)
 {
     if ($this->redis->scard($index) == 1) {
         return $this->redis->del($index);
     }
     return $this->redis->srem($index, $id);
 }
Пример #3
0
 /**
  * @param SessionInterface $session
  * @param Request $request
  */
 private function preRequestHandle(SessionInterface $session, Request $request)
 {
     $id = $request->cookie($this->key);
     $key = 'session:' . $id;
     if (!Str::equals($key, $session->getId())) {
         $this->redis->del($key);
         return;
     }
     $value = $this->redis->get('session:' . $key);
     $content = Json::parse($value);
     if ($content['last_seen'] > $session->get('last_seen')) {
         foreach ($content as $key => $value) {
             if (!Str::startsWith($key, ['_', 'login_'])) {
                 $session->set($key, $value);
             }
         }
     }
 }
Пример #4
0
 /**
  * Release the lock if we possess it.
  *
  * Returns true if we released the lock, and false if it was already
  * released.
  *
  * @return bool
  */
 public function release()
 {
     if (!$this->locked()) {
         return false;
     }
     $this->redis->del($this->name);
     $this->state = self::UNLOCKED;
     return true;
 }
Пример #5
0
 /**
  * Delete all keys from the cache
  *
  * @param bool $check if true will check expiration, otherwise delete all
  * @return bool True if the cache was successfully cleared, false otherwise
  */
 public function clear($check)
 {
     if ($check) {
         return true;
     }
     $keys = $this->client->keys($this->_config['prefix'] . '*');
     foreach ($keys as $key) {
         $this->client->del($key);
     }
     return true;
 }
Пример #6
0
 private function deleteGlob($pattern)
 {
     $keys = $this->client->keys($pattern);
     $options = $this->client->getOptions();
     if (isset($options->prefix)) {
         $length = strlen($options->prefix->getPrefix());
         $keys = array_map(function ($key) use($length) {
             return substr($key, $length);
         }, $keys);
     }
     if (count($keys) === 0) {
         return;
     }
     $this->client->del($keys);
 }
Пример #7
0
 /**
  * @group redis-strings
  */
 public function testSet()
 {
     $this->assertEquals('OK', $this->client->set('foo', 'bar'));
     $this->assertEquals('OK', $this->client->set('foo', 'baz'));
     $this->assertSame('baz', $this->client->get('foo'));
     // EX expire time
     $this->assertEquals('OK', $this->client->set('foo', 'bar', 'EX', 20));
     $this->assertThat($this->client->ttl('foo'), $this->logicalAnd($this->greaterThan(0), $this->lessThanOrEqual(20)));
     // PX expire time
     $this->client->del('foo');
     $this->assertEquals('OK', $this->client->set('foo', 'bar', 'PX', 20000));
     $this->assertThat($this->client->ttl('foo'), $this->logicalAnd($this->greaterThan(0), $this->lessThanOrEqual(20)));
     $this->client->del('foo');
     $this->assertNull($this->client->set('foo', 'bar', 'XX'));
     $this->assertEquals('OK', $this->client->set('foo', 'baz', 'NX'));
     $this->assertNull($this->client->set('foo', 'blue', 'NX'));
     $this->assertEquals('OK', $this->client->set('foo', 'red', 'XX'));
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function destroy($sessionId)
 {
     $this->redis->del($sessionId);
     return true;
 }
Пример #9
0
 /**
  * {@inheritdoc}
  */
 protected function doDelete($id)
 {
     return $this->client->del($id) >= 0;
 }
Пример #10
0
 /**
  * @param array $keys
  *
  * @return void
  */
 public function deleteMulti(array $keys)
 {
     $this->client->del($keys);
     $this->addMultiDeleteAccessStats($keys);
 }
Пример #11
0
 /**
  * {@inheritDoc}
  */
 public function del($key)
 {
     return $this->predis->del($key);
 }
Пример #12
0
 /**
  * Destroy Session - remove data from resource for
  * given session id
  * @param string $id
  * @return void
  */
 public function destroy($id)
 {
     $this->redisClient->del($id);
 }