当前位置: 首页>>代码示例>>PHP>>正文


PHP Redis::ping方法代码示例

本文整理汇总了PHP中Redis::ping方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::ping方法的具体用法?PHP Redis::ping怎么用?PHP Redis::ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::ping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPing

 public function testPing()
 {
     $this->assertEquals('+PONG', $this->redis->ping());
     $count = 1000;
     while ($count--) {
         $this->assertEquals('+PONG', $this->redis->ping());
     }
 }
开发者ID:stonegithubs,项目名称:phpredis,代码行数:8,代码来源:TestRedis.php

示例2: isConnected

 public function isConnected()
 {
     try {
         $status = $this->redis->ping();
         return $status == '+PONG';
     } catch (RedisException $e) {
         return false;
     }
 }
开发者ID:everlution,项目名称:redlock,代码行数:9,代码来源:PhpRedisAdapter.php

示例3: ping

 /**
  * Check if we are still connected to the cache server, reconnect if not.
  *
  * @return bool
  */
 private function ping()
 {
     if (!$this->connected) {
         return false;
     }
     switch (NN_CACHE_TYPE) {
         case self::TYPE_REDIS:
             try {
                 return (bool) $this->server->ping();
             } catch (\RedisException $error) {
                 // nothing to see here, move along
             }
             break;
         case self::TYPE_MEMCACHED:
             $versions = $this->server->getVersion();
             if ($versions) {
                 foreach ($versions as $version) {
                     if ($version != "255.255.255") {
                         return true;
                     }
                 }
             }
             break;
         case self::TYPE_APC:
             return true;
         default:
             return false;
     }
     $this->connect();
     return $this->connected;
 }
开发者ID:RickDB,项目名称:newznab-tmux,代码行数:36,代码来源:Cache.php

示例4: getConnection

 /**
  * Return redis connection object
  *
  * @return  mixed  Redis connection object on success, void or boolean on failure
  *
  * @since   3.4
  *
  * @throws  RuntimeException
  */
 protected function getConnection()
 {
     if (static::isSupported() == false) {
         return false;
     }
     $config = JFactory::getConfig();
     $app = JFactory::getApplication();
     $caching = (bool) $config->get('caching');
     if ($caching == false) {
         return false;
     }
     $this->_persistent = $config->get('redis_persist', true);
     $server = array('host' => $config->get('redis_server_host', 'localhost'), 'port' => $config->get('redis_server_port', 6379), 'auth' => $config->get('redis_server_auth', null), 'db' => (int) $config->get('redis_server_db', null));
     static::$_redis = new Redis();
     if ($this->_persistent) {
         try {
             $connection = static::$_redis->pconnect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (Exception $e) {
         }
     } else {
         try {
             $connection = static::$_redis->connect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (Exception $e) {
         }
     }
     if ($connection == false) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis connection failed');
         }
         return;
     }
     if ($auth == false) {
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis authentication failed');
         }
         return;
     }
     $select = static::$_redis->select($server['db']);
     if ($select == false) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis failed to select database');
         }
         return;
     }
     try {
         static::$_redis->ping();
     } catch (RedisException $e) {
         static::$_redis = null;
         if ($app->isAdmin()) {
             JError::raiseWarning(500, 'Redis ping failed');
         }
         return;
     }
     return static::$_redis;
 }
开发者ID:klas,项目名称:joomla-cms,代码行数:68,代码来源:redis.php

示例5: __construct

 private function __construct($config)
 {
     if ($config == 'REDIS_DEFAULT') {
         $conf['server'] = C('REDIS_HOST');
         $conf['port'] = C('REDIS_PORT');
     } else {
         $conf = C($config);
     }
     $this->redis = new Redis();
     try {
         $this->redis->connect($conf['server'], $conf['port']);
         $this->redis->ping();
     } catch (Exception $e) {
         throw_exception("RedisHandle_redis_connect 3 " . $e->getMessage());
     }
     return $this->redis;
 }
开发者ID:WALES7CH,项目名称:TP-Admin,代码行数:17,代码来源:RedisHandler.class.php

示例6: ping

 /**
  * 查看redis连接是否断开
  * @return $return bool true:连接未断开 false:连接已断开
  */
 public static function ping()
 {
     $redis = new \Redis();
     $redis->connect(self::_HOST, self::_PORT);
     $return = null;
     $return = $redis->ping();
     $redis->close();
     $redis = null;
     return 'PONG' ? true : false;
 }
开发者ID:skyshow,项目名称:ticket,代码行数:14,代码来源:MyRedis.class.php

示例7: ping

 /**
  * Redis supports ping'ing the server, so use it.
  */
 private function ping()
 {
     if ($this->isRedis === true) {
         try {
             return (bool) $this->server->ping();
         } catch (\RedisException $error) {
             $this->connect();
             return $this->connected;
         }
     }
     return true;
 }
开发者ID:sebst3r,项目名称:nZEDb,代码行数:15,代码来源:Cache.php

示例8: __construct

 /**
  * @param array $servers
  * @param string $prefix
  */
 public function __construct($servers, $prefix = '')
 {
     $this->_redis = new Redis();
     // setting default params
     if (!is_array($servers) || empty($servers)) {
         $servers = array(array('host' => 'localhost'));
     }
     foreach ($servers as $server) {
         $port = isset($server['port']) ? $server['port'] : 6379;
         $persist = isset($server['persist']) ? $server['persist'] : false;
         $timeout = isset($server['timeout']) ? $server['timeout'] : '2.5';
         if ($persist) {
             $this->_redis->pconnect($server['host'], $port, $timeout);
         } else {
             $this->_redis->connect($server['host'], $port, $timeout);
         }
     }
     if ($this->_redis->ping() !== '+PONG') {
         throw new Exception('Unable to connect redis server.');
     }
     $this->_prefix = $prefix;
 }
开发者ID:melihucar,项目名称:lime-cache,代码行数:26,代码来源:RedisDriver.php

示例9: checkClientConnection

 /**
  * Check if the Redis client connection is still up and reconnect if Redis was disconnected
  *
  * @return void
  * @throws JobQueueException
  */
 protected function checkClientConnection()
 {
     $reconnect = false;
     try {
         $pong = $this->client->ping();
         if ($pong === false) {
             $reconnect = true;
         }
     } catch (\RedisException $e) {
         $reconnect = true;
     }
     if ($reconnect) {
         if (!$this->connectClient()) {
             throw new JobQueueException('Could not connect to Redis', 1467382685);
         }
     }
 }
开发者ID:flowpack,项目名称:jobqueue-redis,代码行数:23,代码来源:RedisQueue.php

示例10: getConnection

 /**
  * Create the Redis connection
  *
  * @return  Redis|boolean  Redis connection object on success, boolean on failure
  *
  * @since   3.4
  * @note    As of 4.0 this method will throw a JCacheExceptionConnecting object on connection failure
  */
 protected function getConnection()
 {
     if (static::isSupported() == false) {
         return false;
     }
     $config = JFactory::getConfig();
     $app = JFactory::getApplication();
     $this->_persistent = $config->get('redis_persist', true);
     $server = array('host' => $config->get('redis_server_host', 'localhost'), 'port' => $config->get('redis_server_port', 6379), 'auth' => $config->get('redis_server_auth', null), 'db' => (int) $config->get('redis_server_db', null));
     static::$_redis = new Redis();
     if ($this->_persistent) {
         try {
             $connection = static::$_redis->pconnect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (RedisException $e) {
             JLog::add($e->getMessage(), JLog::DEBUG);
         }
     } else {
         try {
             $connection = static::$_redis->connect($server['host'], $server['port']);
             $auth = !empty($server['auth']) ? static::$_redis->auth($server['auth']) : true;
         } catch (RedisException $e) {
             JLog::add($e->getMessage(), JLog::DEBUG);
         }
     }
     if ($connection == false) {
         static::$_redis = null;
         throw new JCacheExceptionConnecting('Redis connection failed', 500);
     }
     if ($auth == false) {
         static::$_redis = null;
         throw new JCacheExceptionConnecting('Redis authentication failed', 500);
     }
     $select = static::$_redis->select($server['db']);
     if ($select == false) {
         static::$_redis = null;
         throw new JCacheExceptionConnecting('Redis failed to select database', 500);
     }
     try {
         static::$_redis->ping();
     } catch (RedisException $e) {
         static::$_redis = null;
         throw new JCacheExceptionConnecting('Redis ping failed', 500);
     }
     return static::$_redis;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:54,代码来源:redis.php

示例11: checkSlave

 public function checkSlave()
 {
     $redis = new Redis();
     $date = date('Y-m-d H:i:s');
     $servers = $this->expansion_conf->getServers();
     foreach ($servers as $s_v) {
         $_host = $s_v['host'];
         $_port = $s_v['port'];
         echo "[{$date}]Redis {$_host}:{$_port}'s dbsize is ";
         $available = $redis->connect($_host, $_port, 0.1);
         if (!$available || '+PONG' !== $redis->ping()) {
             echo "ERR";
         } else {
             echo "[{$redis->dbsize()}]";
         }
         echo "\n";
     }
 }
开发者ID:sdgdsffdsfff,项目名称:twemproxy-redis-helper,代码行数:18,代码来源:redisExpansion.php

示例12: _write_cache

 public function _write_cache($output)
 {
     $CI =& get_instance();
     $path = $CI->config->item('cache_path');
     $cache_path = $path === '' ? APPPATH . 'cache/' : $path;
     $uri = $CI->config->item('base_url') . $CI->config->item('index_page') . $CI->uri->uri_string();
     if ($CI->config->item('cache_query_string') && !empty($_SERVER['QUERY_STRING'])) {
         $uri .= '?' . $_SERVER['QUERY_STRING'];
     }
     $cache_path .= md5($uri);
     $redis = new Redis();
     $host = $CI->config->item("redis_host");
     $port = $CI->config->item("redis_port");
     $redis->connect($host, $port);
     if (!$redis->ping()) {
         log_message('error', "Unable to ping to redis {$host}:{$port}");
         return false;
     }
     if ($this->_compress_output === TRUE) {
         $output = gzencode($output);
         if ($this->get_header('content-type') === NULL) {
             $this->set_content_type($this->mime_type);
         }
     }
     $expire = time() + $this->cache_expiration;
     $cache_info = serialize(array('last_modified' => time(), 'expire' => $expire, 'headers' => $this->headers));
     $output = $cache_info . 'ENDCI--->' . $output;
     try {
         $redis->set($cache_path, $output);
         $redis->expire($cache_path, $this->cache_expiration);
         $this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
     } catch (RedisException $e) {
         log_message('error', "Unable to set cache key");
         return false;
     }
 }
开发者ID:richwandell,项目名称:Codeigniter-Example-App,代码行数:36,代码来源:MY_Output.php

示例13: array

    preg_match_all('%<h[0-6]%', $new_rule_file, $headings);
    $toc_height = (count($headings[0]) ?: 0) * 30;
    $response->render('views/rules.php', array("rules" => $new_rule_file, "toc_height" => $toc_height));
});
respond('/changes/[i:old]/[i:member_id]/[*:view_key]', function ($request, $response) {
    $old = $request->param('old');
    $member_id = $request->param('member_id', false);
    $view_key = substr($request->param('view_key', false), 7);
    $response->cookie('rule_set', $old);
    if ($member_id) {
        $response->cookie('rule_member_id', $member_id);
        if (is_numeric($member_id)) {
            $redis = new Redis();
            $redis->connect(REDIS_IP, REDIS_PORT);
            $redis->auth(REDIS_AUTH);
            if (!$redis->ping()) {
                die('aw no redis :(');
            }
            $redis->lPush('users', json_encode(array("member_id" => $member_id, "time" => time(), "view_key" => $view_key)));
        }
    }
    $response->redirect('/', 301);
});
respond('/compile/[*:secure_key]', function ($request, $response) {
    $secure_key = $request->param('secure_key', false);
    if ($secure_key != SECURE_KEY) {
        die('invalid secure key');
    }
    $time = time();
    $rule_sets = array_slice(scandir('rules'), 2);
    $all_rules = "<!-- compiled at " . $time . " -->" . "\n\n";
开发者ID:notcitricsquid,项目名称:rules,代码行数:31,代码来源:index.php

示例14: open

 /**
  * 打开SESSION
  *
  * @param string $savePath    SESSION保存的路径
  * @param string $sessionName SESSION的KEY
  *
  * @return bool true/false
  */
 public function open($savePath, $sessionName)
 {
     return $this->redis->ping();
 }
开发者ID:3032441712,项目名称:person,代码行数:12,代码来源:Data.php

示例15: Redis

<?php

//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//查看服务是否运行
echo "<hr/>";
echo "Server is running: " . $redis->ping();
echo "<hr/>";
//Connection to server sucessfully
//Server is running: PONG
#############################################
//$redis->set('thename','heruyi');
//var_dump($redis->get('myname'));
#############################################
//带生存时间的写入值
//$redis->setex('myname',20,'heruyi');
//var_dump($redis->get('myname'));
#############################################
//hash key value
//$redis->hset('office','oonane','yunachen');
//var_dump($redis->get('office'));
##############################################
//delete
//$redis->delete('thename')
################################################
//$redis->hset('tj','a',0);
//$rs=$redis->hget('tj','a');
//var_dump($rs);
/*$redis->hIncrBy('tj','a',1);
开发者ID:ruyicoder,项目名称:php,代码行数:31,代码来源:redis.php


注:本文中的Redis::ping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。