memcache内部key的需取出

作者:吴炳锡 来源:http://www.mysqlsupport.cn/ 转载请注明作/译者和出处,并且不能用于商业用途,违者必究。

memcache 查看状态支持的命令:
[code]

1. stats
2. stats reset
3. stats malloc
4. stats maps
5. stats sizes
6. stats slabs
7. stats items
8. stats cachedump slab_id limit_num
9. stats detail [onoffdump]

[/code]

执行stats cachedump 3 0命令。这里的3表示上面图中items后面的数字,0标示显示全部的数据,如果是1就标示只显示1条。

一个例程:
[code]


1.
2. $host=’192.168.15.225′;
3. $port=11211;
4. $mem=new Memcache();
5. $mem->connect($host,$port);
6. $items=$mem->getExtendedStats (‘items’);
7. $items=$items[“$host:$port”][‘items’];
8. for($i=0,$len=count($items);$i<$len;$i++){
9. $number=$items[$i][‘number’];
10. $str=$mem->getExtendedStats (“cachedump”,$number,0);
11. $line=$str[“$host:$port”];
12. if( is_array($line) && count($line)>0){
13. foreach($line as $key=>$value){
14. echo $key.’=>’;
15. print_r($mem->get($key));
16. echo “\r\n”;
17. }
18. }
19. }
20. ?>
[/code]