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);

 

posted @ 2015-01-29 16:22  追风筝的人  Views(693)  Comments(0Edit  收藏  举报