本文整理汇总了PHP中Redis::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::set方法的具体用法?PHP Redis::set怎么用?PHP Redis::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::set方法的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
/**
* Store data on the cache server.
*
* @param string $key Key we can use to retrieve the data.
* @param string|array $data Data to store on the cache server.
* @param int $expiration Time before the data expires on the cache server.
*
* @return bool Success/Failure.
* @access public
*/
public function set($key, $data, $expiration)
{
if ($this->connected === true && $this->ping() === true) {
return $this->server->set($key, $this->isRedis ? $this->IgBinarySupport ? igbinary_serialize($data) : serialize($data) : $data, $expiration);
}
return false;
}
示例3: 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);
}
示例4: 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);
}
}
示例5: 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));
}
}
示例6: save
/**
* Save item in the cache.
*
* @param string $key
* @param string $value
* @param int $ttl
* @return void
*
* @throws StorageException if storage error occurs, handler can not be used
*/
protected function save($key, $value, $ttl)
{
try {
$this->redis->set($key, $value, $ttl);
} catch (\Exception $e) {
throw new StorageException("Failed to save redis key: {$key}", 1, $e);
}
}
示例7: set
/**
* Set a value in the cache
* @param string $p_sKey The Key
* @param mixed $p_mData The Data
* @param mixed $p_mTTL The Time To Live. Integer or String (strtotime)
* @return boolean True on succes, False on failure.
*/
function set($p_sKey, $p_mData, $p_mTTL = null)
{
if ($p_mTTL !== null && is_string($p_mData)) {
$p_mTTL = strtotime($p_mTTL);
}
$p_mTTL = $p_mTTL !== null ? $p_mTTL : $this->_defaults['expiry'];
return $this->_handler->set($p_sKey, $p_mData, $p_mTTL);
}
示例8: 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);
}
}
示例9: set
public function set($key, $value, $ttl = null)
{
if (!is_null($ttl)) {
return $this->connection->set($key, $value, $ttl);
} else {
return $this->connection->set($key, $value);
}
}
示例10: set
public function set($id, $data, $lifetime = false)
{
if ($lifetime) {
return $this->_redis->setex($id, $lifetime, $data);
} else {
return $this->_redis->set($id, $data);
}
}
示例11: 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);
}
}
示例12: store
/**
* @inheritdoc
*/
public function store($key, $value, $ttl = null)
{
$key = $this->prefix . $key;
if ($ttl) {
$this->redis->set($key, serialize($value), $ttl);
return;
}
$this->redis->set($key, serialize($value));
}
示例13: setJson
/**
* 设置值(string)会将$value自动转为json格式
* @param string $key KEY名称
* @param string|array $value 获取得到的数据
* @param int $timeOut 时间
* @return bool
*/
public function setJson($key, $value, $timeOut = 0)
{
$value = json_encode($value);
$retRes = $this->redis->set($key, $value);
if ($timeOut > 0) {
$this->redis->setTimeout($key, $timeOut);
}
return $retRes;
}
示例14: 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;
}
示例15: testStdClass
public function testStdClass()
{
$data = new \stdClass();
$data->a = 'a';
$data->b = 'b';
$key = new CacheKey('test', rand(1, 1000));
$this->cache->set($key, $data);
$val = $this->cache->get($key);
$this->assertEquals($data, $val);
}