PHP實現查詢Memcache記憶體中的所有鍵與值

來源:互聯網
上載者:User

標籤:

  使用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=‘width:30%‘>";25             echo $key;26             echo "</td>";27             echo "<td style=‘width: 70%‘>";28             var_dump($mem->get($key));29             echo "</td>";30             echo "</tr>";31         }32         echo "</table>";33     }34 }

顯示效果:

 

PHP實現查詢Memcache記憶體中的所有鍵與值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.