本文整理汇总了PHP中Redis::expire方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::expire方法的具体用法?PHP Redis::expire怎么用?PHP Redis::expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::expire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
public function set($index, $value)
{
$this->redis->lset($this->key, $index, $value);
if ($this->timeout) {
$this->redis->expire($this->key, $this->timeout);
}
return $this;
}
示例2: acquireLock
/**
* {@inheritdoc}
*/
public function acquireLock($lockId)
{
if ($this->conn->setnx($lockId, 1)) {
$this->conn->expire($lockId, $this->lockTtl);
return true;
}
return false;
}
示例3: set
/**
* Store a value for a given key in the cache.
*
* This method does not check if there is a value available for the given key, may cause unexpected behavior if not.
* Use has() to prevent this issue.
*
* @param string $key
* @param array $tags
* @param mixed $data
*/
public function set($key, array $tags, $data)
{
$key = $this->redis->prefix($key);
$this->redis->set($key, $this->encoder->encode($data));
if (is_int($this->expirationTime) && $this->expirationTime > 0) {
$this->redis->expire($key, $this->expirationTime);
}
foreach ($tags as $tag) {
$this->redis->sadd($this->redis->prefix($tag), $key);
}
}
示例4: setTTL
public function setTTL($key, $ttl)
{
if (!$this->isConnected()) {
return false;
}
if (!$this->exists($key)) {
return false;
}
if (!is_numeric($ttl)) {
throw new InvalidTtlException($ttl);
}
return $this->redis->expire($key, (int) $ttl);
}
示例5: set
/**
* Set a value identified by $key and with an optional $ttl.
*
* @param string $key
* @param mixed $value
* @param int $ttl
*
* @return $this
*/
public function set($key, $value, $ttl = 0)
{
$ttl = $this->fromDefaultTtl($ttl);
if ($ttl >= 0) {
if ($this->isAvailable()) {
$this->redis->set($key, $this->storageDataStructure($value));
if ($ttl > 0) {
$this->redis->expire($key, $ttl);
}
}
$this->setChain($key, $value, $ttl);
}
return $this;
}
示例6: lockSession
/**
* @param string $sessionId
*/
private function lockSession($sessionId)
{
$attempts = 1000000 / $this->spinLockWait * $this->lockMaxWait;
$this->lockKey = $sessionId . '.lock';
for ($i = 0; $i < $attempts; $i++) {
$success = $this->redis->setnx($this->prefix . $this->lockKey, '1');
if ($success) {
$this->locked = true;
$this->redis->expire($this->prefix . $this->lockKey, $this->lockMaxWait + 1);
return true;
}
usleep($this->spinLockWait);
}
return false;
}
示例7: expire
/**
* @param string $key
* @param int $ttl
* @return bool
*/
public function expire($key, $ttl)
{
$this->_useCnt++;
return $this->_wrapBoolReturn(function () use($key, $ttl) {
return parent::expire($key, $ttl);
});
}
示例8: incrBy
public function incrBy($chiave, $valore = 1, $scadenza = Cache::SCADENZA_DEFAULT)
{
$x = parent::incrBy($chiave, $valore);
if ($scadenza) {
parent::expire($chiave, $scadenza);
}
return $x;
}
示例9: appendValue
/**
* 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);
}
示例10: setCached
protected function setCached(Bookmark $bookmark, $redisKey)
{
if ($this->redis !== null) {
$this->redis->hSet($redisKey, $bookmark->url, 1);
if ($this->redis->ttl($redisKey) < 0) {
$this->redis->expire($redisKey, 4 * 7 * 24 * 60 * 60);
}
}
}
示例11: set
/**
* Set an item in the cache
*
* @param string $key
* @param mixed $value
* @param int|\DateInterval|\DateTime $validity Number of seconds this is valid for (if int)
* @return void
*/
function set($key, $value, $validity = null)
{
$this->connection->set($key, $value);
if ($validity instanceof \DateInterval) {
$validity = (new \DateTimeImmutable())->add($validity);
}
if ($validity instanceof \DateTimeInterface) {
$this->connection->expireat($key, $validity->getTimestamp());
} else {
if (is_numeric($validity)) {
$this->connection->expire($key, $validity);
} else {
if ($validity != null) {
throw new \UnexpectedValueException("Unexpected validity");
}
}
}
}
示例12: touch
/**
* Set the last modified time to the current time
*
* @return bool Success status
*/
public function touch()
{
$data = $this->cache->get($this->name);
if ($data !== false) {
$return = $this->cache->set($this->name, $data);
if ($this->options['expire']) {
return $this->cache->expire($this->name, $this->ttl);
}
return $return;
}
return false;
}
示例13: test4_set2
function test4_set2()
{
$cache = new Redis();
$cache->pconnect('127.0.0.1', 7001);
$t1 = microtime(1);
for ($i = 0; $i < 10000; $i++) {
$cache->set('qwe' . $i, 'hello' . $i);
$cache->expire('qwe' . $i, 1800);
}
$t2 = microtime(1);
var_dump($t2 - $t1);
echo "\n";
}
示例14: testPersist
public function testPersist()
{
$this->redis->set('x', 'y');
$this->redis->expire('x', 100);
$this->assertTrue(TRUE === $this->redis->persist('x'));
// true if there is a timeout
$this->assertTrue(-1 === $this->redis->ttl('x'));
// -1: timeout has been removed.
$this->assertTrue(FALSE === $this->redis->persist('x'));
// false if there is no timeout
$this->redis->del('x');
$this->assertTrue(FALSE === $this->redis->persist('x'));
// false if the key doesn’t exist.
}
示例15: write
/**
* Write data to the session.
*
* @param string $id
* @param mixed $data
* @return bool
*/
public function write($id, $data)
{
// This might be the first set for this session key, so we have to check if it's already exists in redis
if ($this->_id !== $id) {
// Perform getset to check if session already exists in redis
if ($this->_redis->getSet($this->_buildKey($id), $data) === false) {
// session doesn't exists in redis, so we have to set expiration
$this->_redis->expire($this->_buildKey($id), $this->_config['lifetime']);
}
// Backup id, so we'll know that expiration has already been set, we'll avoid to perform getset on the next write
$this->_id = $id;
} else {
// This is not the first write in script execution, just update value
$this->_redis->set($this->_buildKey($id), $data);
}
return true;
}