当前位置 : 主页 > 网络编程 > PHP >

php memcache 基本操作

来源:互联网 收集:自由互联 发布时间:2021-07-03
!DOCTYPE htmlhtml head titlememcache demo/title meta http-equiv="content-type" content="text/html;chatset=utf-8" /head body ?php $server_ip = '127.0.0.1'; $server_port = 11211; $memcache = new Memcache(); $memcache-connect($server_ip,$serve
 
<!DOCTYPE html>
<html>
    <head>
        <title>memcache demo</title>
        <meta http-equiv="content-type" content="text/html;chatset=utf-8">
    </head>
    <body>
        <?php
            $server_ip = '127.0.0.1';
            $server_port = 11211;
  
            $memcache = new Memcache();
            $memcache->connect($server_ip,$server_port);
              
            $memcache->add("name1","user_name1",MEMCACHE_COMPRESSED,0);
            $memcache->add("name2","user_name2",MEMCACHE_COMPRESSED,0);
            $array1 = array('name1' => 'jiajiam1', 
                            'age1'=>12,
                            'country'=>'china');
            $memcache->add("other",$array1,MEMCACHE_COMPRESSED,20);
            $memcache->set("name3","user_name3",MEMCACHE_COMPRESSED,0);
            $memcache->replace("name1","user_name_relpace",MEMCACHE_COMPRESSED,0);
            $memcache->replace("123","12345");
  
            echo "name1:".$memcache->get("name1")."<br/>";
            $memcache->delete("name1");
            echo "name1:".$memcache->get("name1")."<br/>";
  
            $array_get = array("name1","name2","name3");
  
            $result_get = $memcache->get($array_get);
            foreach ($result_get as $key => $value) {
                echo "$key:--->$value<br/>";
            }
            foreach ($memcache->getStats() as $key => $value) {
                echo "$key:--->$value<br/>";   
            };
  
            echo "<br/>";
  
            foreach($memcache->getExtendedStats() as $key => $value) {
                echo "$key:--->$value<br/>";
            }
            $memcache->close();
        ?>
    </body>
</html>

网友评论