首页 > 代码库 > redis和memcache列出所有key
redis和memcache列出所有key
//redis$redis = new Redis();$redis->connect("host", "port");$redis->select(0); //redis默认有0-15 16个数据库 此处选择0$redis->dbsize(); //返回有多少个key$keys = $redis->keys("*"); //使用通配符列出所有keyvar_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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。