예제 #1
1
 public function set($sKey, $oData, $iTTL = -1)
 {
     $iTTL = $this->buildTTL($iTTL);
     if ($iTTL === 0) {
         return $this->oClient->set($this->buildKey($sKey), $this->serialize($oData));
     }
     return $this->oClient->setex($this->buildKey($sKey), $iTTL, $this->serialize($oData));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function set($key, $data, $ttl = 0)
 {
     if ($ttl > 0) {
         return $this->redis->setex($key, (int) $ttl, $data);
     }
     return $this->redis->set($key, $data);
 }
예제 #3
0
 public function set($id, $data, $lifetime = false)
 {
     if ($lifetime) {
         return $this->_redis->setex($id, $lifetime, $data);
     } else {
         return $this->_redis->set($id, $data);
     }
 }
예제 #4
0
 /**
  * Stores item in Redis.
  *
  * @param \iveeCore\ICacheable $item to be stored
  *
  * @return boolean true on success
  */
 public function setItem(ICacheable $item)
 {
     $ttl = $item->getCacheExpiry() - time();
     if ($ttl < 1) {
         return false;
     }
     return $this->redis->setex($item->getKey(), $ttl, gzencode(serialize($item)));
 }
예제 #5
0
 /**
  * @param int $userId
  *
  * @return string
  */
 public function createUserToken($userId)
 {
     $generator = new SecureRandom();
     $rand = $generator->nextBytes(12);
     $wsseToken = sha1($rand);
     $this->redis->setex(self::PREFIX . ':' . $userId, $this->ttl, $wsseToken);
     return $wsseToken;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     if (0 === $lifeTime) {
         return $this->_redis->set($id, $data);
     } else {
         return $this->_redis->setex($id, $lifeTime, $data);
     }
 }
예제 #7
0
 /**
  * @inheritdoc
  */
 public function put($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return $this->redis->setex($key, $ttl, $value);
     } else {
         return $this->redis->set($key, $value);
     }
 }
예제 #8
0
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return self::$cache->setex($this->getNamespace() . $key, $ttl, json_encode($value));
     } else {
         return self::$cache->set($this->getNamespace() . $key, json_encode($value));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     if (0 < $this->ttl) {
         $this->redis->setex($this->getRedisKey($sessionId), $this->ttl, $data);
     } else {
         $this->redis->set($this->getRedisKey($sessionId), $data);
     }
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = false)
 {
     if (0 < $lifeTime) {
         $result = $this->redis->setex($id, (int) $lifeTime, serialize($data));
     } else {
         $result = $this->redis->set($id, serialize($data));
     }
     return (bool) $result;
 }
예제 #11
0
 /**
  * Stores item in Redis.
  *
  * @param \iveeCrest\ICacheable $item to be stored
  *
  * @return boolean true on success
  */
 public function setItem(ICacheable $item)
 {
     $key = md5($this->uniqId . '_' . $item->getKey());
     $ttl = $item->getCacheTTL();
     //emulate memcached behaviour: TTLs over 30 days are interpreted as (absolute) UNIX timestamps
     if ($ttl > 2592000) {
         $this->redis->set($key, serialize($item));
         return $this->redis->expireAt($key, $ttl);
     } else {
         return $this->redis->setex($key, $ttl, serialize($item));
     }
 }
예제 #12
0
	/**
	 * 设置缓存
	 * @param string $cache_id
	 * @param mixed $data 缓存数据
	 * @param int $left 缓存时间 秒
	 * @return bool
	 */
	public function set($cache_id, $data, $left = 60) {
		try {
			$value = serialize($data);
			if ($left === 0) {
				$retRes = $this->_redis->set($cache_id, $value);
			} else {
				$retRes = $this->_redis->setex($cache_id, $left, $value);
			}
			return $retRes;
		} catch (Exception $e) {
			$this->_error = $e->getMessage();
			return false;
		}
	}
예제 #13
0
 public function testExpireAtWithLong()
 {
     $longExpiryTimeExceedingInt = 3153600000.0;
     $this->redis->delete('key');
     $this->assertTrue($this->redis->setex('key', $longExpiryTimeExceedingInt, 'val') === TRUE);
     $this->assertTrue($this->redis->ttl('key') === $longExpiryTimeExceedingInt);
 }
예제 #14
0
 /**
  * Store some data in session.
  * Expects a session id and the data to write.
  * @param string $sessionId
  * @param mixed $data
  * @return boolean
  */
 public function write($sessionId = '', $data = '')
 {
     if ($sessionId !== '') {
         $this->_redis->setex($this->_key($sessionId), $this->_lifetime, $data);
     }
     return true;
 }
예제 #15
0
 /**
  * Write session data
  *
  * @param   string  $session_id    The session id
  * @param   string  $session_data  The encoded session data
  *
  * @return  boolean  True on success, false otherwise
  *
  * @since   __DEPLOY_VERSION__
  */
 public function write($session_id, $session_data)
 {
     if ($this->ttl > 0) {
         return $this->redis->setex($this->prefix . $session_id, $this->ttl, $session_data);
     }
     return $this->redis->set($this->prefix . $session_id, $session_data);
 }
예제 #16
0
파일: WsseProvider.php 프로젝트: bzis/zomba
 /**
  * @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;
 }
예제 #17
0
 /**
  * {@inheritdoc}
  */
 protected function getLock($name, $blocking)
 {
     $content = serialize($this->getLockInformation());
     if ($this->expiration > 0) {
         if (!$this->redis->setex($name, $this->expiration, $content)) {
             return false;
         }
         $this->ttl[$name] = $this->expiration;
     } else {
         if (!$this->redis->setnx($name, $content)) {
             return false;
         }
         unset($this->ttl[$name]);
     }
     return true;
 }
예제 #18
0
 public function testSetEx()
 {
     $this->redis->delete('key');
     $this->assertTrue($this->redis->setex('key', 7, 'val') === TRUE);
     $this->assertTrue($this->redis->ttl('key') === 7);
     $this->assertTrue($this->redis->get('key') === 'val');
 }
예제 #19
0
파일: Cache.php 프로젝트: pizar/gaia
 /**
  * Riscrive la funzione set, con scadenza forzata automaticamente
  * ad un giorno
  */
 public function set($chiave, $valore, $scadenza = Cache::SCADENZA_DEFAULT)
 {
     if (!$scadenza) {
         parent::set($chiave, $valore);
     } else {
         parent::setex($chiave, $scadenza, $valore);
     }
 }
예제 #20
0
파일: redis.php 프로젝트: eshiol/joomla-cms
 /**
  * Store the data to cache by ID and group
  *
  * @param   string  $id     The cache data ID
  * @param   string  $group  The cache data group
  * @param   string  $data   The data to store in cache
  *
  * @return  boolean
  *
  * @since   3.4
  */
 public function store($id, $group, $data)
 {
     if (static::isConnected() == false) {
         return false;
     }
     static::$_redis->setex($this->_getCacheId($id, $group), $this->_lifetime, $data);
     return true;
 }
예제 #21
0
파일: CRedis.php 프로젝트: nbaiwan/yav
 public function setex($key, $timeout = 0, $value = null, $dependency = null)
 {
     if ($dependency !== null) {
         $dependency->evaluateDependency();
     }
     $data = array($value, $dependency);
     return parent::setex($this->generateUniqueKey($key), $timeout, serialize($data));
 }
예제 #22
0
 /**
  * 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);
 }
예제 #23
0
 /**
  * Write data for key into cache.
  *
  * @param string $key Identifier for the data
  * @param mixed $value Data to be cached
  * @param int $duration How long to cache the data, in seconds
  * @return bool True if the data was successfully cached, false on failure
  */
 public function write($key, $value, $duration)
 {
     if (!is_int($value)) {
         $value = serialize($value);
     }
     if ($duration === 0) {
         return $this->_Redis->set($key, $value);
     }
     return $this->_Redis->setex($key, $duration, $value);
 }
예제 #24
0
 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     if ($this->locking) {
         if (!$this->locked) {
             if (!$this->lockSession($sessionId)) {
                 return false;
             }
         }
     }
     $this->redis->setex($this->getRedisKey($sessionId), $this->ttl, $data);
 }
 /**
  * Write data for key into cache if it doesn't exist already.
  * If it already exists, it fails and returns false.
  *
  * @param string $key Identifier for the data.
  * @param mixed $value Data to be cached.
  * @param int $duration How long to cache the data, in seconds.
  * @return bool True if the data was successfully cached, false on failure.
  * @link https://github.com/phpredis/phpredis#setnx
  */
 public function add($key, $value, $duration)
 {
     if (!is_int($value)) {
         $value = serialize($value);
     }
     $result = $this->_Redis->setnx($key, $value);
     // setnx() doesn't have an expiry option, so overwrite the key with one
     if ($result) {
         return $this->_Redis->setex($key, $duration, $value);
     }
     return false;
 }
예제 #26
0
 /**
  * Write data for key into cache.
  *
  * @param string $key Identifier for the data
  * @param mixed $value Data to be cached
  * @return bool True if the data was successfully cached, false on failure
  */
 public function write($key, $value)
 {
     $key = $this->_key($key);
     if (!is_int($value)) {
         $value = serialize($value);
     }
     $duration = $this->_config['duration'];
     if ($duration === 0) {
         return $this->_Redis->set($key, $value);
     }
     return $this->_Redis->setex($key, $duration, $value);
 }
예제 #27
0
 /**
  * Write data for key into cache if it doesn't exist already.
  * If it already exists, it fails and returns false.
  *
  * @param string $key Identifier for the data.
  * @param mixed $value Data to be cached.
  * @return bool True if the data was successfully cached, false on failure.
  * @link https://github.com/phpredis/phpredis#setnx
  */
 public function add($key, $value)
 {
     $duration = $this->_config['duration'];
     $key = $this->_key($key);
     if (!is_int($value)) {
         $value = serialize($value);
     }
     // setnx() doesn't have an expiry option, so overwrite the key with one
     if ($this->_Redis->setnx($key, $value)) {
         return $this->_Redis->setex($key, $duration, $value);
     }
     return false;
 }
예제 #28
0
 /**
  * Save cache
  *
  * @param	string	$id	Cache ID
  * @param	mixed	$data	Data to save
  * @param	int	$ttl	Time to live in seconds
  * @param	bool	$raw	Whether to store the raw value (unused)
  * @return	bool	TRUE on success, FALSE on failure
  */
 public function save($id, $data, $ttl = 60, $raw = FALSE)
 {
     if (is_array($data) or is_object($data)) {
         if (!$this->_redis->sAdd('_ci_redis_serialized', $id)) {
             return FALSE;
         }
         isset($this->_serialized[$id]) or $this->_serialized[$id] = TRUE;
         $data = serialize($data);
     } elseif (isset($this->_serialized[$id])) {
         $this->_serialized[$id] = NULL;
         $this->_redis->sRemove('_ci_redis_serialized', $id);
     }
     return $ttl ? $this->_redis->setex($id, $ttl, $data) : $this->_redis->set($id, $data);
 }
예제 #29
0
 /**
  * 写入key-value
  * @param $key string 要存储的key名
  * @param $value mixed 要存储的值
  * @param $time longint 过期时间(S)  默认值为0-不设置过期时间
  * @return $return bool true:成功 flase:失败
  */
 public static function set($key, $value, $time = 0)
 {
     $redis = new \Redis();
     $redis->connect(self::_HOST, self::_PORT);
     $return = null;
     if ($time && is_numeric($time)) {
         $return = $redis->setex($key, $time, $value);
     } else {
         $return = $redis->set($key, $value);
     }
     $redis->close();
     $redis = null;
     return $return;
 }
예제 #30
0
파일: Redis.php 프로젝트: ehough/stash
 /**
  * {@inheritdoc}
  */
 public function storeData($key, $data, $expiration)
 {
     $store = serialize(array('data' => $data, 'expiration' => $expiration));
     if (is_null($expiration)) {
         return $this->redis->set($this->makeKeyString($key), $store);
     } else {
         $ttl = $expiration - time();
         // Prevent us from even passing a negative ttl'd item to redis,
         // since it will just round up to zero and cache forever.
         if ($ttl < 1) {
             return true;
         }
         return $this->redis->setex($this->makeKeyString($key), $ttl, $store);
     }
 }