本文整理汇总了PHP中Redis::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::exists方法的具体用法?PHP Redis::exists怎么用?PHP Redis::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exists
public function exists($key)
{
if (!$this->isConnected()) {
return false;
}
return (bool) $this->redis->exists($key);
}
示例2: testExists
public function testExists()
{
$key = 'key' . rand();
$this->assertFalse($this->redis->exists($key));
$this->redis->add($key, 'val');
$this->assertTrue($this->redis->exists($key));
}
示例3: getMy
/**
* @param $key
* @return Option
*/
public static function getMy($key)
{
$hash = self::hash($key);
if (self::$redis->exists(self::myPrefix() . ":" . $hash)) {
return Option::Some(unserialize(self::$redis->get(self::myPrefix() . ":" . $hash)));
} else {
return Option::None();
}
}
示例4: getHashes
/**
* Returns a list of all affected hashes for a given set of tags.
*
* @param array $tags
*
* @return array
*/
private function getHashes(array $tags)
{
$hashes = [];
foreach ($tags as $tag) {
$tag = $this->redis->prefix($tag);
if (!$this->redis->exists($tag)) {
continue;
}
$hashes = array_merge($hashes, $this->redis->smembers($tag));
}
return array_unique($hashes);
}
示例5: getWithFallback
/**
* Try to get an item, and if missed call the fallback method to produce the value and store it.
*
* @param string $key
* @param callable $fallback
* @param int|\DateInterval|\DateTime|callback $validity Number of seconds this is valid for (if int)
* @return mixed
*/
function getWithFallback($key, callable $fallback, $validity = null)
{
$value = $this->connection->get($key);
if (!$value && !$this->connection->exists($key)) {
$value = $fallback();
if (is_callable($validity)) {
$validity = call_user_func($validity, $value);
}
$this->set($key, $value, $validity);
return $value;
}
return $value;
}
示例6: isFrozen
/**
* Tells if this backend is frozen.
*
* @return boolean
*/
public function isFrozen()
{
if (null === $this->frozen) {
$this->frozen = $this->redis->exists($this->buildKey('frozen'));
}
return $this->frozen;
}
示例7: 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;
}
示例8: _display_cache
public function _display_cache(&$CFG, &$URI)
{
$cache_path = $CFG->item('cache_path') === '' ? APPPATH . 'cache/' : $CFG->item('cache_path');
$uri = $CFG->item('base_url') . $CFG->item('index_page') . $URI->uri_string;
if ($CFG->item('cache_query_string') && !empty($_SERVER['QUERY_STRING'])) {
$uri .= '?' . $_SERVER['QUERY_STRING'];
}
$filepath = $cache_path . md5($uri);
$redis = new Redis();
$host = $CFG->item("redis_host");
$port = $CFG->item("redis_port");
$redis->connect($host, $port);
if ($redis->exists($filepath)) {
$cache = $redis->get($filepath);
if (!preg_match('/^(.*)ENDCI--->/', $cache, $match)) {
return false;
}
} else {
return false;
}
$cache_info = unserialize($match[1]);
$expire = $cache_info['expire'];
$last_modified = $cache_info["last_modified"];
$this->set_cache_header($last_modified, $expire);
foreach ($cache_info['headers'] as $header) {
$this->set_header($header[0], $header[1]);
}
$this->_display(substr($cache, strlen($match[0])));
log_message('debug', 'Cache is current. Sending it to browser.');
return TRUE;
}
示例9: removeWord
/**
* {@inheritDoc}
*/
public function removeWord($language, $word)
{
$word = mb_strtolower($word, mb_detect_encoding($word));
if ($this->redis->exists($word)) {
$languages = unserialize($this->redis->get($word));
if (false !== ($index = array_search($language, $languages))) {
unset($languages[$index]);
if (!count($languages)) {
$this->redis->del($word);
} else {
$this->redis->set($word, serialize($languages));
}
}
}
return $this;
}
示例10: testExists
public function testExists()
{
$this->redis->delete('key');
$this->assertFalse($this->redis->exists('key'));
$this->redis->set('key', 'val');
$this->assertEquals(True, $this->redis->exists('key'));
}
示例11: exists
/**
* key是否存在,存在返回ture
* @param string $cache_id KEY名称
*/
public function exists($cache_id) {
try {
return $this->_redis->exists($cache_id);
} catch (Exception $e) {
$this->_error = $e->getMessage();
return false;
}
}
示例12: 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);
}
示例13: destroy
/**
* 摧毁SESSION
*
* @param int $id key
*
* @return bool true/false
*/
public function destroy($id)
{
$id = 'sess_' . $id;
if ($this->redis->exists($id)) {
return $this->redis->delete($id);
}
return true;
}
示例14: find
/**
* {@inheritDoc}
*/
public function find($storageName, $key)
{
$key = $this->getKeyName($key);
if (!$this->client->exists($key)) {
throw new NotFoundException();
}
return json_decode($this->client->get($key), true);
}
示例15: destroy
/**
* Destroy a session.
* Expects a session id.
* @param string $sessionId
* @return boolean
*/
public function destroy($sessionId = '')
{
if ($sessionId !== '' && $this->_redis->exists($this->_key($sessionId))) {
$this->_redis->del($this->_key($sessionId));
}
session_destroy();
return true;
}