黑马程序员技术交流社区

标题: 【上海校区】关于memcache的一道笔试题 [打印本页]

作者: 爱编码的J    时间: 2019-4-11 16:35
标题: 【上海校区】关于memcache的一道笔试题
题目:memcache配置:host:localhost;port:11211;
memcache key:uid_1、uid_2、uid_3、uid_4、uid_5、uid_6、uid_7、uid_8、uid_9、uid_10
写一段代码,请以效率最高的方式查询出上述10个key的数据(需写出从连接memcache开始到结束的完整过程)

具体代码:
[PHP] 纯文本查看 复制代码
<?php
$host='Localhost';
$port=11211;
$mem=new Memcache();
$mem->connect($host,$port);
$items=$mem->getExtendedStats (‘items’);
$items=$items[$host,$port]['items'];
foreach($items as $key=>$values){
$number='uid_'.$key;
$str=$mem->getExtendedStats ("cachedump",$number,10);
$line=$str["$host:$port"];
if( is_array($line) && count($line)>0){
foreach($line as $key=>$value){
$mem->get($key);
}
}
}
?>






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2