本文整理汇总了PHP中Predis\Client::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::set方法的具体用法?PHP Client::set怎么用?PHP Client::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* {@inheritdoc}
*/
public function save()
{
$contents = $this->getForStorage();
$this->client->set($this->key, $contents);
if ($this->expire !== null) {
$this->client->expire($this->key, $this->expire);
}
}
示例2: set
/**
* @inheritdoc
*/
public function set($key, $value, $ttl = 0)
{
if ($ttl > 0) {
return $this->predis->setex($key, $ttl, $value);
}
return $this->predis->set($key, $value);
}
示例3: cache
/**
* {@inheritDoc}
*/
public function cache(BatchGeocoded $geocoded)
{
$this->redis->set($key = $this->getKey($geocoded->getProviderName(), $geocoded->getQuery()), $this->serialize($geocoded));
if ($this->expire > 0) {
$this->redis->expire($key, $this->expire);
}
}
示例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: stringWrite
/**
* Write a string value to storage
* @param string $key the key
* @param string $value the string value to be written
* @param null|int $timeout an optional timout in milliseconds
* @return string redis result
*/
public function stringWrite($key, $value, $timeout = null)
{
$result = $this->_redis->set($key, $value);
if ($timeout !== null) {
$this->_redis->pexpire($key, $timeout);
}
return $result;
}
示例6: store
/**
* @param Password $password
* @param bool $allowOverwrite
*/
public function store(Password $password, $allowOverwrite = false)
{
if (!$allowOverwrite && $this->get($password->getId())) {
throw new PhPsstException('The ID already exists', PhPsstException::ID_IS_ALREADY_TAKEN);
}
$this->client->set($password->getId(), $password->getJson());
$this->client->expireat($password->getId(), $password->getTtl());
}
示例7: add
/**
* @param $key
* @param $value
* @throws UnavailableException
*/
public function add($key, $value)
{
// encrypt the tokens before storing in redis
try {
$this->client->set($key, $this->encryption->encrypt($value));
} catch (ServerException $ex) {
throw new UnavailableException($ex->getMessage());
}
}
示例8: getCurrentOrderAction
public function getCurrentOrderAction(Application $app)
{
// Pause the execution until the display is updated
while (true === json_decode($this->client->get(BogoBogoSorter::DISPLAYED_KEY))) {
usleep(500);
}
$this->client->set(BogoBogoSorter::DISPLAYED_KEY, json_encode(true));
return $app->json(json_decode($this->client->get(BogoBogoSorter::DATA_KEY), true));
}
示例9: set
/**
* * Add a value to the cache under a unique key
*
* @param string $key
* @param mixed $value
* @param int $ttl
*/
public function set($key, $value, $ttl = null)
{
$this->client->set($key, $value);
if ($ttl) {
$cmd = $this->client->createCommand('EXPIRE');
$cmd->setArguments(array($key, $ttl));
$this->client->executeCommand($cmd);
}
}
示例10: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, $data, $lifeTime = 0)
{
if ($lifeTime > 0) {
$response = $this->client->setex($id, $lifeTime, $data);
} else {
$response = $this->client->set($id, $data);
}
return $response === true || $response == 'OK';
}
示例11: save
/**
* @param Widget $widget
* @param $content
*/
public function save(Widget $widget, $content)
{
$hash = $this->getHash($widget);
if ($hash) {
$this->redis->set($hash, $content);
$this->redis->expire($hash, $this->widgetHelper->getCacheTimeout($widget));
// cache for a week
}
}
示例12: 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;
}
示例13: save
/**
* {@inheritdoc}
*/
public function save($id, $data, $lifeTime = 0)
{
if ($lifeTime > 0) {
$response = $this->client->setex($this->prefix . $id, $lifeTime, $data);
} else {
$response = $this->client->set($this->prefix . $id, $data);
}
return $response === true || $response == 'OK';
}
示例14: checkWriteToStorage
/**
* @return void
*/
private function checkWriteToStorage()
{
try {
$this->client->set(self::KEY_HEARTBEAT, 'ok');
} catch (\Exception $e) {
$this->addDysfunction(self::HEALTH_MESSAGE_UNABLE_TO_WRITE_TO_STORAGE);
$this->addDysfunction($e->getMessage());
}
}
示例15: save
/**
* @param AbstractJob $job
*
* @return bool
* @throws \Cronario\Exception\JobException
*/
public function save(AbstractJob $job)
{
$data = $job->getData();
if (!$job->isStored()) {
$job->setId(uniqid());
}
$this->redis->set($this->namespace . $job->getId(), json_encode($data));
return true;
}