本文整理汇总了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());
}
}
示例2: isConnected
public function isConnected()
{
try {
$status = $this->redis->ping();
return $status == '+PONG';
} catch (RedisException $e) {
return false;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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";
}
}
示例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;
}
}
示例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";
示例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();
}
示例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);