本文整理汇总了PHP中Predis\Client::expire方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::expire方法的具体用法?PHP Client::expire怎么用?PHP Client::expire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::expire方法的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: 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);
}
}
示例3: createRate
public function createRate($key, $limit, $period)
{
$this->client->hset($key, 'limit', $limit);
$this->client->hset($key, 'calls', 1);
$this->client->hset($key, 'reset', time() + $period);
$this->client->expire($key, $period);
return $this->getRateInfo($key);
}
示例4: write
/**
* Writes session data.
*
* @param string $id A session ID
* @param string $data A serialized chunk of session data
*
* @return bool true, if the session was written, otherwise an exception is thrown
*
* @throws \RuntimeException If the session data cannot be written
*/
public function write($key, $data)
{
$result = $this->db->hset($this->getHashKey(), $key, serialize($data));
$expires = (int) $this->options['lifetime'];
if ($expires > 0) {
$this->db->expire($this->getHashKey(), $expires);
}
return $result;
}
示例5: 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
}
}
示例6: set
/**
* {@inheritDoc}
*/
public function set($key, $value, $namespace = KeyValue::DEFAULT_NAMESPACE, $expirationDateTime = KeyValue::NO_EXPIRE)
{
$effectiveKey = $this->buildKey($key, $namespace);
$this->redisClient->set($effectiveKey, serialize($value));
$keyValue = new KeyValue($key, $value, $namespace, $expirationDateTime);
if ($expirationDateTime !== KeyValue::NO_EXPIRE) {
$this->redisClient->expire($effectiveKey, $keyValue->getSecsToExpire());
}
return $keyValue;
}
示例7: write
public function write($key, $value, $expires = null)
{
$key = $this->prefix . $key;
$this->store->set($key, serialize($value));
if (isset($expires)) {
$expires = $this->makeExpiry($expires);
$this->store->expire($key, $expires);
}
$this->addToIndex($key, $expires);
return $this;
}
示例8: set
public function set($id, $value, $ttl = null)
{
try {
$this->redis->set($id, $value);
if ($ttl) {
$this->redis->expire($id, $ttl);
}
return true;
} catch (Predis\PredisException $e) {
return false;
}
}
示例9: set
/**
* {@inheirtdoc}
*
* @return \Orno\Cache\Adapter\RedisAdapter
*/
public function set($key, $data, $expiry = null)
{
if (is_null($expiry)) {
$expiry = $this->getExpiry();
}
if (is_string($expiry)) {
$expiry = $this->convertExpiryString($expiry);
}
$this->redis->set($key, $data);
$this->redis->expire($key, $expiry);
return $this;
}
示例10: 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;
}
示例11: listen
/**
* Start the worker and wait for requests
*/
public function listen()
{
$context = new \ZMQContext();
$server = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
$server->bind('tcp://127.0.0.1:' . ($this->defaultPort + $this->client->getId() - 1));
$this->logger->info('Client worker ' . $this->client . ' is ready');
while (true) {
$request = $server->recv();
$this->logger->debug('Client worker ' . $this->client . ' receiving request : ' . $request);
// Check if the input is valid, ignore if wrong
$request = json_decode($request, true);
if (!$this->isValidInput($request)) {
$this->logger->error('Client worker ' . $this->client . ' received an invalid input');
continue;
}
try {
// Call the right method in the client and push to redis the result
$result = call_user_func_array(array($this->client, $request['command']), $request['parameters']);
} catch (ClientNotReadyException $e) {
$this->logger->warning('Client worker ' . $this->client . ' received a request (#' . $request['invokeId'] . ') whereas the client is not ready. This is normal in case of client reconnection process. Ignoring.');
continue;
}
$key = $this->key . '.client.commands.' . $request['invokeId'];
$this->redis->rpush($key, serialize($result));
$this->redis->expire($key, $this->expire);
}
}
示例12: setHistorySessionToRedis
/**
* @param $sid
* @param $session
*/
public function setHistorySessionToRedis($sid, $session)
{
$key = $this->getHistoryKey($sid);
$this->redis->set($key, serialize($session));
$this->redis->expire($key, 60 * 60 * 24 * 30);
// preserve 30 days
}
示例13: 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);
}
示例14: getWithName
/**
* @param $key
* @param $queryName
* @param array $options
*
* @return org_glizy_dataAccess_cache_Iterator
*/
public function getWithName($key, $queryName, $options = array())
{
$data = $this->redis->get($key);
if ($data == null) {
$data = array();
/** @var org_glizy_dataAccess_cache_Iterator $it */
$it = org_glizy_ObjectFactory::createModelIterator($this->model, $queryName, $options);
/** @var org_glizy_dataAccess_cache_ActiveRecord $ar */
foreach ($it as $ar) {
$data[] = $ar->getValuesAsArray();
}
$this->redis->set($key, $this->serialize($data));
} else {
$data = $this->unserialize($data);
}
if ($this->lifeTime != -1) {
$this->redis->expire($key, $this->lifeTime);
}
return new org_glizy_dataAccess_cache_Iterator($data);
}
示例15: set
/**
* Set cache value
*
* @param CacheKey $key
* @param mixed $value
* @param int $sessionLength
*/
public function set(CacheKey $key, $value, $sessionLength = null)
{
if ($sessionLength == null) {
$sessionLength = $this->timeThreshold;
}
$sKey = $this->getKey($key);
if (is_array($value) || is_object($value)) {
$value = serialize($value);
}
$this->redis->set($sKey, $value);
if (!empty($sessionLength) && $sessionLength > 0) {
$this->redis->expire($sKey, $sessionLength);
}
}