redis和memcache列出所有key

//redis
$redis = new Redis();
$redis->connect("host", "port");
$redis->select(0);  //redis默认有0-15 16个数据库 此处选择0
$redis->dbsize();   //返回有多少个key
$keys = $redis->keys("*"); //使用通配符列出所有key
var_dump($keys);


//memcache
$servers = array(array("host1", "port1"), array("host2", "port2"));
$mem = new Memcache();
$mem->addServer("host1", "port1");
$mem->addServer("host2", "port2");
$all_items = $memcache->getExtendedStats(‘items‘);
$options = array("host1:port1","host2:port2");
foreach($servers as $server){ $option = $server[0] . ":" . $server[1]; if(isset($all_items[$option][‘items‘])) { $items = $all_items[$option][‘items‘]; foreach ($items as $number => $item) { $str = $memcache->getExtendedStats(‘cachedump‘, $number, 0); $line = $str[$option]; if(is_array($line) && count($line) > 0){ foreach ($line as $key=>$value) { $keys[] = $key; } } } } } var_dump($keys);

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。