function srvc_redis_dump_info() { // https://github.com/phpredis/phpredis#close $redis = new Redis(); $redis->connect('127.0.0.1'); $redis_info = $redis->info(); $redis->close(); $json = json_encode($redis_info); echo "{$json}"; }
/** * {@inheritdoc} */ protected function doGetStats() { $stats = $this->redis->info(); $statsHits = isset($stats['keyspace_hits']) ? $stats['keyspace_hits'] : $stats['Stats']['keyspace_hits']; $statsMisses = isset($stats['keyspace_misses']) ? $stats['keyspace_misses'] : $stats['Stats']['keyspace_misses']; $statsMemoryUsage = isset($stats['used_memory']) ? $stats['used_memory'] : $stats['Memory']['used_memory']; $statsUptime = isset($stats['uptime_in_seconds']) ? $stats['uptime_in_seconds'] : $stats['Server']['uptime_in_seconds']; return array(Cache::STATS_HITS => $statsHits, Cache::STATS_MISSES => $statsMisses, Cache::STATS_UPTIME => $statsUptime, Cache::STATS_MEMORY_USAGE => $statsMemoryUsage, Cache::STATS_MEMORY_AVAILIABLE => null); }
/** * @inheritdoc */ public function status() { $info = $this->redis->info(); $status[self::HITS] = 0; $status[self::MISSES] = 0; $status[self::START_TIME] = isset($info['uptime_in_seconds']) ? $info['uptime_in_seconds'] : 0; $status[self::MEMORY_USED] = isset($info['used_memory']) ? $info['used_memory'] : 0; $status[self::MEMORY_LEFT] = 0; return $status; }
/** * Constructor * * Instantiate the memcache cache object * * @param int $lifetime * @param string $host * @param int $port * @throws Exception * @return Redis */ public function __construct($lifetime = 0, $host = 'localhost', $port = 6379) { parent::__construct($lifetime); if (!class_exists('Redis', false)) { throw new Exception('Error: Redis is not available.'); } $this->redis = new \Redis(); if (!$this->redis->connect($host, (int) $port)) { throw new Exception('Error: Unable to connect to the memcached server.'); } $this->version = $this->redis->info()['redis_version']; }
/** * {@inheritDoc} * * @link https://github.com/phpredis/phpredis#info * * Does some minor transformation to ensure a baseline of info between Memcache and Redis */ protected function _getStats() { $info = $this->_connection->info(); // Ensure info keyspace is populated before returning $defaults = ['keyspace_hits' => 0, 'keyspace_misses' => 0, 'evicted_keys' => 0, 'maxmemory' => 0, 'process_id' => 0, 'uptime_in_seconds' => 0, 'lru_clock' => 0, 'redis_version' => 0, 'total_system_memory' => 0, 'connected_clients' => 0, 'total_commands_processed' => 0, 'total_net_input_bytes' => 0, 'total_net_output_bytes' => 0]; $info = array_merge($defaults, $info); $info['get_hits'] = $info['keyspace_hits']; $info['get_misses'] = $info['keyspace_misses']; $info['evictions'] = $info['evicted_keys']; $info['pointer_size'] = $info['maxmemory']; $info['pid'] = $info['process_id']; $info['uptime'] = $info['uptime_in_seconds']; $info['time'] = $info['lru_clock']; $info['version'] = $info['redis_version']; $info['bytes'] = 0; $info['bytes_read'] = $info['total_net_output_bytes']; $info['bytes_written'] = $info['total_net_input_bytes']; $info['limit_maxbytes'] = $info['total_system_memory']; $info['curr_items'] = 0; $info['total_items'] = 0; $info['curr_connections'] = $info['connected_clients']; $info['total_connections'] = $info['total_commands_processed']; $info['cmd_get'] = $info['keyspace_hits']; $info['cmd_set'] = 0; return $info; }
/** * 查看全部服务器 */ private function _overview_all() { $info = array(); foreach ($this->server_list as $i => $server) { if (isset($server['cluster_list'])) { $info[$i]['error'] = FALSE; $info[$i]['cluster_list'] = $server['cluster_list']; continue; } $redis = new Redis(); $can_connect = FALSE; try { $can_connect = $redis->connect($server['host'], $server['port'], 0.5); } catch (Exception $e) { $can_connect = TRUE; } $info[$i] = array('error' => FALSE); if (!$can_connect) { $info[$i]['error'] = TRUE; } else { $info[$i] = array_merge($info[$i], $redis->info()); $info[$i]['size'] = $redis->dbSize(); } } $page_data['info'] = $info; $page_data['server_list'] = $this->server_list; $page_data['title'] = '服务器一览表'; $this->load->view('overview', $page_data); }
/** * Scan and variants */ protected function get_keyspace_count($str_db) { $arr_info = $this->redis->info(); $arr_info = $arr_info[$str_db]; $arr_info = explode(',', $arr_info); $arr_info = explode('=', $arr_info[0]); return $arr_info[1]; }
public function testinfo() { $info = $this->redis->info(); $keys = array("redis_version", "arch_bits", "uptime_in_seconds", "uptime_in_days", "connected_clients", "connected_slaves", "used_memory", "changes_since_last_save", "bgsave_in_progress", "last_save_time", "total_connections_received", "total_commands_processed", "role"); foreach ($keys as $k) { $this->assertTrue(in_array($k, array_keys($info))); } }
/** * Get cache server statistics. * * @return array|string * @access public */ public function serverStatistics() { if ($this->connected === true && $this->ping() === true) { if ($this->isRedis === true) { return $this->server->info(); } else { return $this->server->getStats(); } } return array(); }
/** * @return void * @throws CacheException */ protected function verifyRedisVersionIsSupported() { // Redis client could be in multi mode, discard for checking the version $this->redis->discard(); $serverInfo = $this->redis->info(); if (!isset($serverInfo['redis_version'])) { throw new CacheException('Unsupported Redis version, the Redis cache backend needs at least version ' . self::MIN_REDIS_VERSION, 1438251553); } if (version_compare($serverInfo['redis_version'], self::MIN_REDIS_VERSION) < 0) { throw new CacheException('Redis version ' . $serverInfo['redis_version'] . ' not supported, the Redis cache backend needs at least version ' . self::MIN_REDIS_VERSION, 1438251628); } }
public function testInfoCommandStats() { // INFO COMMANDSTATS is new in 2.6.0 if (version_compare($this->version, "2.5.0", "lt")) { $this->markTestSkipped(); } $info = $this->redis->info("COMMANDSTATS"); $this->assertTrue(is_array($info)); if (is_array($info)) { foreach ($info as $k => $value) { $this->assertTrue(strpos($k, 'cmdstat_') !== false); } } }
/** * Skip the test if the Redis extension is unavailable. * * @return void */ public function skip() { $this->skipIf(!Redis::enabled(), 'The redis extension is not installed.'); $redis = new RedisCore(); $cfg = $this->_config; try { $redis->connect($cfg['host'], $cfg['port']); } catch (Exception $e) { $info = $redis->info(); $msg = "redis-server does not appear to be running on {$cfg['host']}:{$cfg['port']}"; $this->skipIf(!$info, $msg); } unset($redis); }
/** * Get cache server statistics. * * @return array * @access public */ public function serverStatistics() { if ($this->ping()) { switch (NN_CACHE_TYPE) { case self::TYPE_REDIS: return $this->server->info(); case self::TYPE_MEMCACHED: return $this->server->getStats(); case self::TYPE_APC: return apc_cache_info(); } } return array(); }
/** * Get cache status * * @return array */ public function status() { $enabled = $this->isEnabled(); if (!$enabled) { return array("provider" => "phpredis", "enabled" => $enabled, "objects" => null, "options" => array()); } $objects = 0; $options = array(); $this->resetErrorState(); try { $objects = $this->instance->dbSize(); $options = $this->instance->info(); } catch (RedisException $re) { $this->raiseError("Server unreachable (PhpRedis), exiting gracefully", array("RESULTCODE" => $re->getCode(), "RESULTMESSAGE" => $re->getMessage())); $this->setErrorState(); $enabled = false; } return array("provider" => "phpredis", "enabled" => $enabled, "objects" => $objects, "options" => $options); }
/** * 连接数据库方法 * @access public */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $redis = new Redis(); $redis->connect($config["REDIS_HOST"] ? $config["REDIS_HOST"] : "localhost", $config["REDIS_PORT"] ? $config["REDIS_PORT"] : 6379); $redis->auth($config["REDIS_AUTH"] ? $config["REDIS_AUTH"] : ""); $info = $redis->info(); // 标记连接成功 if (!empty($info["redis_version"])) { $this->linkID[$linkNum] = $redis; $this->connected = true; } // 注销数据库连接配置信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
private static function getMasterInfo() {/*{{{*/ $sentinelIps = BeanFinder::get('redisConfigs'); //支持dev环境 if($sentinelIps[0] == '127.0.0.1') { return array('ip' => $sentinelIps[0], 'port' => $sentinelIps[1]); } $redis = new Redis(); foreach($sentinelIps as $sentinelIp) { if($redis->connect($sentinelIp, self::SENTINEL_PORT)) { $info = $redis->info('Sentinel'); if(preg_match('#address=(?<ip>[\d,.]+):(?<port>\d+),#', $info['master0'], $matches)) { return array('ip' => $matches['ip'], 'port' => $matches['port']); } } } throw new SystemException('redis sentinel 全挂了'); }/*}}}*/
/** * Get cache driver info * * @param string Not supported in Redis. * Only included in order to offer a * consistent cache API. * @return array * @see Redis::info() */ public function cache_info($type = NULL) { return $this->_redis->info(); }
public function testGetCapabilitiesTtl() { $host = defined('TESTS_ZEND_CACHE_REDIS_HOST') ? TESTS_ZEND_CACHE_REDIS_HOST : '127.0.0.1'; $port = defined('TESTS_ZEND_CACHE_REDIS_PORT') ? TESTS_ZEND_CACHE_REDIS_PORT : 6379; $redisResource = new RedisResource(); $redisResource->connect($host, $port); $info = $redisResource->info(); $mayorVersion = (int) $info['redis_version']; $this->assertEquals($mayorVersion, $this->_options->getResourceManager()->getMayorVersion($this->_options->getResourceId())); $capabilities = $this->_storage->getCapabilities(); if ($mayorVersion < 2) { $this->assertEquals(0, $capabilities->getMinTtl(), 'Redis version < 2.0.0 does not support key expiration'); } else { $this->assertEquals(1, $capabilities->getMinTtl(), 'Redis version > 2.0.0 supports key expiration'); } }
<?php $redis = new Redis(); $redisException = new RedisException(); var_dump($redisException); $redis->flushDB(); $redis->info(); $redis->info("COMMANDSTATS"); $redis->ifno("CPU"); $redis->lastSave(); $redis->resetStat(); $redis->save(); $redis->slaveof('10.0.1.7', 6379); $redis->slowlog('get', 10); $redis->slowlog('reset'); $redis->get('key'); $redis->get('key'); $redis->set('key', 'value', 10); $redis->set('key', 'value', array('nx', 'ex' => 10)); $redis->set('key', 'value', array('xx', 'px' => 1000)); $redis->setex('key', 3600, 'value'); $redis->psetex('key', 100, 'value'); $redis->setnx('key', 'value'); $redis->set('key1', 'val1'); $redis->set('key2', 'val2'); $redis->set('key3', 'val3'); $redis->set('key4', 'val4'); $redis->delete('key1', 'key2'); /* return 2 */ $redis->delete(array('key3', 'key4')); /* return 2 */
var plotarea = $("#placeholder2'; echo $i; echo '"); plotarea.css("height", "120px"); plotarea.css("width", "450px"); $.plot(plotarea, data, options); }); </script> '; $i++; } echo "</div>"; ?> <hr/> <a href="?clear-all-data=true" class="red-button pcb"><span>Clear All Data</span></a> <?php $info = $r->info(); $mem = $info['used_memory']; $mem = round($mem / 1024, 1); $num_keys = $r->dbsize(); echo "<br><br><p style='color: #556; font-size: 12px'>Memory used: {$mem} KBytes, Number of keys: {$num_keys}"; ?> </body> </html>
public function connect($config = null) { //default $config if (!$config) { $new_config['host'] = '127.0.0.1'; $new_config['port'] = 6379; } //如果$config传过来的值是字符串(host:port) if (!is_array($config)) { $host_port = explode(':', $config); $new_config['host'] = $host_port[0]; $new_config['port'] = $host_port[1]; } else { $new_config = $config; } if (class_exists('redis')) { //设置master链接 $redis = new Redis(); if ($redis) { //连接两次,当第一次失败的时候才会尝试连接第二次 $conn_rs = false; for ($i = 0; $i < 1; $i++) { //当连接发生错误的时候,直接跳到catch执行代码 try { $conn_rs = $redis->connect($new_config['host'], $new_config['port']); break; } catch (Exception $e) { Log::write2('redis cluster connect master 第 ' . ($i + 1) . ' 次 fail for msg(' . $e->getMessage() . ')', 'redisCluster'); } } //1:连接两次都失败,尝试连接slave(master可能宕机了) //2:连接上不一定是master,可能是slave。(当旧master宕机后再重新开启) //获取redis连接信息 $redis_info = $redis->info(); $host = isset($redis_info['master_host']) ? $redis_info['master_host'] : ''; $port = isset($redis_info['master_port']) ? $redis_info['master_port'] : ''; if (!$conn_rs || $host && $port) { $slave_arr = $this->_getSlaveRedis($new_config); try { $conn_rs = $redis->connect($slave_arr[0], $slave_arr[1]); $new_config['host'] = $slave_arr[0]; $new_config['port'] = $slave_arr[1]; } catch (Exception $e) { Log::write2('redis cluster connect slave fail for msg(' . $e->getMessage() . ')', 'redisCluster'); return false; } } //连接到服务器redis的实例是否成功 $this->_link_handle['master_conn'] = $conn_rs; //保存实例 $this->_link_handle['master'] = $redis; //保存当前链接的配置文件 $this->_config['master']['host'] = $new_config['host']; $this->_config['master']['port'] = $new_config['port']; return true; } else { Log::write2('redis cluster connect fail', 'redisCluster'); return false; } } else { Log::write2('not have redis class for redis cluster', 'redisCluster'); return false; } }
function initRedis() { $redis = new Redis(); if ($redis->connect('tools-redis', 6379)) { try { $redis->info("server"); } catch (Exception $e) { $redis = new RedisFake(); } } else { $redis = new RedisFake(); } return $redis; }
/** * Cache Info * * @return mixed array containing cache info on success OR FALSE on failure * @see Redis::info() */ public function cache_info() { return $this->_redis->info(); }
<?php echo '<h3>Redis Caching Driver Test</h3>'; echo 'phpredis version: ' . @phpversion('redis'); echo '<br />'; echo '<br />'; echo '<hr />'; echo '<br />'; echo 'Making a native Redis class instance: '; echo '<br />'; if (!class_exists('Redis')) { die('Can not load redis.'); } $redis = new Redis() or die('Can not load redis.'); $redis->connect('127.0.0.1'); $redis_server_info = $redis->info(); $redis_server_version = $redis_server_info['redis_version']; echo 'Redis server version: ' . $redis_server_version; echo '<br />'; echo '<br />'; echo 'Loading CodeIgniter\'s cache with redis driver.'; echo '<br />'; echo '<br />'; ci()->load->driver('cache', array('adapter' => 'redis')); // Let us see whwther they work. echo 'The following value should increment on every page reload.'; echo '<br />'; ci()->cache->increment('test_key_1'); echo print_d(ci()->cache->get('test_key_1')); echo '<div style="clear: both;"/>'; echo '<br />';
public function getStatistics() { $info = \Redis::info(); return \view('redistree::statistics', ['info' => $info]); }
$response['db_api_version'] = phpversion('mysqli'); if ($is_admin) { require_once __DIR__ . "/../../db.php"; $db_data = db_QueryFetchPair("show VARIABLES like \"%version%\""); $response['db_version'] = $db_data['version']; $db_data = db_QueryFetchPair("show global status where Variable_Name = 'Uptime';"); $response['db_uptime'] = time_offset() + intval($db_data['Uptime']); } } // Redis // if (defined('CMW_USING_REDIS') && $show_redis) { $response['redis_api_version'] = phpversion('redis'); if ($is_admin) { $redis = new Redis(); $redis->connect(CMW_REDIS_HOST); $info = $redis->info('default'); $response['redis_version'] = $info['redis_version']; $response['redis_uptime'] = time_offset() + intval($info['uptime_in_seconds']); $redis->close(); } } // Memcached // if (defined('CMW_USING_MEMCACHED') && $show_memcached) { $response['memcached_api_version'] = phpversion('memcached'); if ($is_admin) { $m = new Memcached(); $m->addServer(CMW_MEMCACHED_HOST, CMW_MEMCACHED_PORT); $m_data = $m->getStats(); //$response['memcached'] = []; // If multiple servers foreach ($m_data as $key => $value) { //$response['memcached'][$key] = $value['uptime']; // If multiple servers
/** * {@inheritdoc} */ protected function doGetStats() { $stats = $this->_redis->info(); return [Cache::STATS_HITS => false, Cache::STATS_MISSES => false, Cache::STATS_UPTIME => $stats['uptime_in_seconds'], Cache::STATS_MEMORY_USAGE => $stats['used_memory'], Cache::STATS_MEMORY_AVAILIABLE => false]; }
echo 6; exit; $master_name = 'my_master'; $sentinel = new \RedisSentinel\Sentinel($master_name); $sentinel->add(new \RedisSentinel\Client('192.168.1.2', 26379)); $sentinel->add(new \RedisSentinel\Client('192.168.1.3', 26379)); $sentinel->add(new \RedisSentinel\Client('192.168.1.4', 26379)); var_dump($sentinel->getMaster()); var_dump($sentinel->getSlaves()); var_dump($sentinel->getSlave()); // Random, one of slaves. exit; $redis = new \Redis(); $redis->connect('127.0.0.1', 26380); $redis->sentinel('get-master-addr-by-name test-master'); print_r($redis->info()); throw new \Exception('testas'); exit; exit; $redis->connect('127.0.0.1', 6379); $redis->set('zzz', 'test-val-2'); $value = $redis->get('zzz'); var_dump($value); //sleep(1); $redis = new Redis(); $redis->connect('127.0.0.1', 6380); //$redis->set('zzz', 'test2'); $value = $redis->get('zzz'); var_dump($value); //sleep(1); $redis = new Redis();
/** * @inheritdoc */ public function info() { return $this->driver->info(); }
/** * @return string */ public function getServerInfo() { return $this->redis->info(); }