本文整理汇总了PHP中Predis\Client::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::exists方法的具体用法?PHP Client::exists怎么用?PHP Client::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasSession
/**
* @param string $sessionId
* @return boolean
*/
public function hasSession($sessionId)
{
if ($this->redis->exists('session_' . $sessionId)) {
return true;
}
return false;
}
示例2: get
/**
* Get a variable
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
{
if ($this->client->exists($this->namespace . $key)) {
return $this->client->get($this->namespace . $key);
} else {
return $default;
}
}
示例3: getUpdatedAt
/**
* {@inheritdoc}
*/
public function getUpdatedAt()
{
if ($this->client->exists('migraine:date')) {
$date = new \DateTime();
$date->setTimestamp(intval($this->client->get('migraine:date')));
return $date;
}
return null;
}
示例4: isCached
/**
* {@inheritDoc}
*/
public function isCached($providerName, $query)
{
if (!$this->redis->exists($key = $this->getKey($providerName, $query))) {
return false;
}
$cached = new BatchGeocoded();
$cached->fromArray($this->deserialize($this->redis->get($key)));
return $cached;
}
示例5: lookupKeyInRedisDatabase
/**
* Checks if the activation key is present in the redis database.
*
* @param string $activationKey
*
* @return bool
*/
private function lookupKeyInRedisDatabase($activationKey)
{
$persistentKey = $this->generateRedisKeyByApprovalKey($activationKey);
$exists = $this->redis->exists($persistentKey);
// the key is not needed anymore because the approval validation will be triggered once only.
if ($exists) {
$this->redis->del($persistentKey);
}
return $exists;
}
示例6: getAvailability
/**
* @inheritdoc
*/
public function getAvailability(\string $id) : \bool
{
$key = sprintf(self::QUANTITY_KEY, $id);
if (!$this->predis->exists($key)) {
$value = $this->repository->getAvailability($id);
$this->saveAvailability($id, $value);
} else {
$value = (int) $this->predis->get($key);
}
return $value;
}
示例7: getById
/**
* @inheritdoc
*/
public function getById(\string $id) : CustomerView
{
$key = self::KEY . ':' . $id;
if ($this->client->exists($key)) {
$item = $this->client->hgetall($key);
$model = $this->createViewModel($item);
} else {
$model = $this->repository->getById($id);
$this->save($model);
}
return $model;
}
示例8: getAllIndexed
/**
* @inheritDoc
*/
public function getAllIndexed() : array
{
if (!$this->client->exists($this->key)) {
$data = $this->repository->getAllIndexed();
if ($data) {
$this->client->hmset($this->key, $data);
}
} else {
$data = $this->client->hgetall($this->key);
}
return $data;
}
示例9: getEventsFor
public function getEventsFor($id)
{
if (!$this->predis->exists('events:' . $id)) {
throw new AggregateDoesNotExist($id);
}
$serializedEvents = $this->predis->lrange('events:' . $id, 0, -1);
$eventStream = [];
foreach ($serializedEvents as $serializedEvent) {
$eventData = $this->serializer->deserialize($serializedEvent, 'array', 'json');
$eventStream[] = $this->serializer->deserialize($eventData['data'], $eventData['type'], 'json');
}
return new EventStream($id, $eventStream);
}
示例10: handle
/**
* @param EventInterface $event
*/
public function handle(EventInterface $event)
{
$this->redis->lpush(self::BUFFER_LIST_KEY, json_encode($event->toArray()));
if ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
$this->redis->pexpire(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS);
} else {
$this->redis->psetex(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS, '1');
while ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
usleep(self::BUFFER_SLEEP_MILLISECONDS);
}
$this->handleBufferedEvents();
}
}
示例11: getFromCache
protected function getFromCache($key)
{
if (!$this->cache->exists($key)) {
return null;
}
return unserialize($this->cache->get($key));
}
示例12: validateDigest
/**
* @param string $digest
* @param string $nonce
* @param string $created
* @param string $secret
*
* @return bool
* @throws \Symfony\Component\Security\Core\Exception\NonceExpiredException
*/
protected function validateDigest($digest, $nonce, $created, $secret)
{
/*
* закомментили 7.01.2014 из-за проблемы возможного расхождения с клиентским временем
*
// Check created time is not in the future
if (strtotime($created) > time()) {
return false;
}
// Expire timestamp after 5 minutes
if (time() - strtotime($created) > self::TTL) {
return false;
}
*/
// Validate nonce is unique within 5 minutes
if ($this->redis->exists(self::PREFIX . ':' . $nonce)) {
if (null !== $this->logger) {
$this->logger->debug(sprintf('Previously used nonce detected: %s', base64_decode($nonce)));
}
throw new NonceExpiredException('Previously used nonce detected');
}
$this->redis->setex(self::PREFIX . ':' . $nonce, self::TTL, time());
// Validate Secret
$expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
if (null !== $this->logger) {
$this->logger->debug(sprintf('[+] %s, [=] %s (created: %s, nonce: %s, secret: %s)', $digest, $expected, $created, base64_decode($nonce), $secret));
}
return $digest === $expected;
}
示例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: testExpireIn
/**
* @covers BehEh\Flaps\Storage\PredisStorage::expireIn
*/
public function testExpireIn()
{
$this->assertEquals(0, $this->client->exists('key'));
$this->assertEquals(0, $this->client->exists('key:timestamp'));
$this->storage->setValue('key', 1);
$this->storage->setTimestamp('key', 1425829426.0);
$this->assertEquals(1, $this->client->exists('key'));
$this->assertEquals(1, $this->client->exists('key:timestamp'));
$this->assertEquals(1, $this->storage->expireIn('key', 0));
$this->assertEquals(0, $this->client->exists('key'));
$this->assertEquals(0, $this->client->exists('key:timestamp'));
$this->assertEquals(0, $this->storage->expireIn('key', 0));
}
示例15: isAllowed
/**
* {@inheritdoc}
* Example:
* <code>
* //Does Andres have access to the customers resource to create?
* $acl->isAllowed('Andres', 'Products', 'create');
* //Do guests have access to any resource to edit?
* $acl->isAllowed('guests', '*', 'edit');
* </code>
*
* @param string $role
* @param string $resource
* @param string $access
*
* @return bool
*/
public function isAllowed($role, $resource, $access)
{
if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
return Acl::ALLOW;
}
if ($this->redis->exists("rolesInherits:{$role}")) {
$rolesInherits = $this->redis->sMembers("rolesInherits:{$role}");
foreach ($rolesInherits as $role) {
if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
return Acl::ALLOW;
}
}
}
/**
* Return the default access action
*/
return $this->getDefaultAction();
}