码迷,mamicode.com
首页 > 系统相关 > 详细

redis和memcache列出所有key

时间:2015-01-29 17:15:15      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:

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

 

redis和memcache列出所有key

标签:

原文地址:http://www.cnblogs.com/Jqxing/p/4260229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!