zoukankan      html  css  js  c++  java
  • PHP实现查询Memcache内存中的所有键与值

      使用Memcache时,我们可以用memcache提供的get方法,通过键查询到当前的数据,但是有时候需要查询内存中所有的键和值,这个时候可以使用下面的代码实现:

     1 <?php
     2 /**
     3  * Created by PhpStorm.
     4  * User: Steven
     5  * Date: 2016/9/22
     6  * Time: 17:21
     7  */
     8 
     9 $host = '127.0.0.1';
    10 $port = 11211;
    11 $mem = new Memcache();
    12 $mem->connect($host, $port);
    13 $items = $mem->getExtendedStats('items');
    14 $items = $items["$host:$port"]['items'];
    15 foreach ($items as $key => $values) {
    16     $number = $key;;
    17     $str = $mem->getExtendedStats("cachedump", $number, 0);
    18     $line = $str["$host:$port"];
    19     if (is_array($line) && count($line) > 0) {
    20         echo "<table border=2>";
    21         echo "<tr><th>键</th><th>值</th></tr>";
    22         foreach ($line as $key => $value) {
    23             echo "<tr>";
    24             echo "<td style='30%'>";
    25             echo $key;
    26             echo "</td>";
    27             echo "<td style=' 70%'>";
    28             var_dump($mem->get($key));
    29             echo "</td>";
    30             echo "</tr>";
    31         }
    32         echo "</table>";
    33     }
    34 }

    显示效果:

  • 相关阅读:
    期末总结
    虚拟存储器学习记录
    实验报告
    并发编程学习记录
    进程&信号&管道实践学习记录
    异常控制流学习记录
    系统级IO实践学习记录
    系统级I/O学习记录
    Arduino小车学习与研究
    期中总结
  • 原文地址:https://www.cnblogs.com/Steven-shi/p/5897597.html
Copyright © 2011-2022 走看看