示例#1
0
 /**
  * @param Password $password
  * @param bool $allowOverwrite
  */
 public function store(Password $password, $allowOverwrite = false)
 {
     if (!$allowOverwrite && $this->get($password->getId())) {
         throw new PhPsstException('The ID already exists', PhPsstException::ID_IS_ALREADY_TAKEN);
     }
     $this->client->set($password->getId(), $password->getJson());
     $this->client->expireat($password->getId(), $password->getTtl());
 }
示例#2
0
 public function expireIn($key, $seconds)
 {
     $redisTime = $this->client->time();
     $at = ceil($redisTime[0] + $seconds);
     $this->client->expireat($this->prefixTimestamp($key), $at);
     return (int) $this->client->expireat($this->prefixKey($key), $at) === 1;
 }
 /**
  * Store association until its expiration time in Redis server. 
  * Overwrites any existing association with same server_url and 
  * handle. Handles list of associations for every server. 
  */
 function storeAssociation($server_url, $association)
 {
     // create Redis keys for association itself
     // and list of associations for this server
     $associationKey = $this->associationKey($server_url, $association->handle);
     $serverKey = $this->associationServerKey($server_url);
     // save association to server's associations' keys list
     $this->redis->lpush($serverKey, $associationKey);
     // Will touch the association list expiration, to avoid filling up
     $newExpiration = $association->issued + $association->lifetime;
     $expirationKey = $serverKey . '_expires_at';
     $expiration = $this->redis->get($expirationKey);
     if (!$expiration || $newExpiration > $expiration) {
         $this->redis->set($expirationKey, $newExpiration);
         $this->redis->expireat($serverKey, $newExpiration);
         $this->redis->expireat($expirationKey, $newExpiration);
     }
     // save association itself, will automatically expire
     $this->redis->setex($associationKey, $newExpiration - time(), serialize($association));
 }
示例#4
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);
                 }
             }
         }
     });
 }