本文整理汇总了PHP中Predis\ClientInterface::setex方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::setex方法的具体用法?PHP ClientInterface::setex怎么用?PHP ClientInterface::setex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::setex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* Write value for a 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);
$value = is_int($value) ? (int) $value : serialize($value);
if ($this->_config['duration'] === 0) {
return (string) $this->client->set($key, $value) === 'OK';
}
return (string) $this->client->setex($key, $this->_config['duration'], $value) === 'OK';
}
示例2: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, $data, $lifeTime = 0)
{
$data = serialize($data);
if ($lifeTime > 0) {
$response = $this->client->setex($id, $lifeTime, $data);
} else {
$response = $this->client->set($id, $data);
}
return $response === true || $response == 'OK';
}
示例3: testSetEx
/**
* @group redis-strings
*/
public function testSetEx()
{
$this->assertEquals('OK', $this->client->setex('foo', 20, 'bar'));
$this->assertEquals('OK', $this->client->setex('foo', 20, 'baz'));
$this->assertSame('baz', $this->client->get('foo'));
$this->assertThat($this->client->ttl('foo'), $this->logicalAnd($this->greaterThan(0), $this->lessThanOrEqual(20)));
}
示例4: set
/**
* @param string $key
* @param mixed $value
* @param int|null $ttl
*
* @throws \Exception
*
* @return mixed
*/
public function set($key, $value, $ttl = null)
{
$key = $this->getKeyName($key);
if ($ttl === null) {
$result = $this->client->set($key, $value);
} else {
$result = $this->client->setex($key, $ttl, $value);
}
$this->addWriteAccessStats($key);
if (!$result) {
throw new \Exception('could not set redisKey: "' . $key . '" with value: "' . json_encode($value) . '"');
}
return $result;
}
示例5: write
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
$this->redis->setex($sessionId, $this->ttl, $data);
return true;
}