本文整理汇总了PHP中Redis::setex方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::setex方法的具体用法?PHP Redis::setex怎么用?PHP Redis::setex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::setex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
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: set
/**
* {@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: set
public function set($id, $data, $lifetime = false)
{
if ($lifetime) {
return $this->_redis->setex($id, $lifetime, $data);
} else {
return $this->_redis->set($id, $data);
}
}
示例4: setItem
/**
* 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: createUserToken
/**
* @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: doSave
/**
* {@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: put
/**
* @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: set
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));
}
}
示例9: write
/**
* {@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: doSave
/**
* {@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: setItem
/**
* 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: set
/**
* 设置缓存
* @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: testExpireAtWithLong
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: write
/**
* 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: write
/**
* 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);
}