$conn = new MongoClient("mongodb://192.168.1.239:27017");
$db = $conn->test; // 选择数据库blog
$collection = $db->menu;
/*$menu = Menu::find()->asArray()->getAll();
foreach($menu as $v)
{ // 新增
$collection->insert($v);
}*/
//$newdata = array('$set' => array("email" => "test@test.com")); // 修改
//$collection->update(array("name" => "caleng"), $newdata);
//$collection->remove(array('name'=>'caleng'), array("justOne" => true)); // 删除
$cursor = $collection->find(); // 查找
// 迭代显示文档标题
foreach ($cursor as $document) {
dump($document);
}
//$user = $collection->findOne(array('name' => 'caleng'), array('name','email')); // 查找一条
//var_dump($user);
$conn->close();
exit;
//$memcache = new Memcache; //创建一个memcache对象
//$memcache->connect('192.168.1.239', 11212) or die ("Could not connect"); //连接Memcached服务器
//$memcache->addServer('192.168.1.239', 11212);
$mem_conf = array(
array('host'=>'192.168.1.239', 'port'=>'11211'),
array('host'=>'192.168.1.239', 'port'=>'11212')
);
$memcache = new Memcache();
foreach ($mem_conf as $v) {
$memcache->addServer($v['host'],$v['port']);
}
$menu = Menu::find()->asArray()->getAll();
foreach($menu as $v)
{
$memcache->set('menu_'.$v['mid'], json_encode($v));
}
//$memcache->set('key4', 'test4'); //设置一个变量到内存中,名称是key 值是test
//$get_value = $memcache->get('key4'); //从内存中取出key的值
//echo $get_value;