php-memcache基本用法

        //create a memcache object
        $mem = new Memcache();

        //create connection
        $mem->connect('localhost',11211);

        //save a value
        $mem->set('key1','This is first value',0,60);

        //save a array
        $arr = array(1,2,3,4,5);
        $mem->set('key2',$arr,0,60);
        print_r($mem);

        //get a value
        $val1 = $mem->get('key');

        //replace the value
        $mem->replace('key1'."This is second value",0,60);

        //delete the value
        $mem->delete('key2');

        //flush all value
        $mem->flush();

        //close connection
        $mem->close();

posted @ 2017-05-17 16:53  Khazix  阅读(200)  评论(0编辑  收藏  举报