PHP memcache single case

Source: Internet
Author: User
    1. Set __construct () to private so that the external new is not allowed
    2. Instantiates an object inside the class. External can be obtained on the line
classMemextendsMemcache{privatestatic$mem_instancenull;    privatefunction__construct(){parent::__construct();    }    privatefunction__clone(){}    publicstaticfunctionget_mem_ins(){if(nullself::$mem_instance){            self::$mem_instancenew Memcache;        }        returnself::$mem_instance;    }}
    1. Memcache operation

   Php//Connection$mem=NewMemcache;$mem -Connect"Db.nowamagic.net",12000);//Save Data$mem -Set(' Key1 ',' This is first value ',0, -);$val=$mem -Get' Key1 '); Echo"Get key1 value:".$val."
"
;//Replace data$mem -Replace' Key1 ',' This is replace value ',0, -);$val=$mem -Get' Key1 '); Echo"Get key1 value:".$val."
"
;//Save array$arr=Array(' AAA ',' BBB ',' CCC ',' DDD ');$mem -Set(' Key2 ',$arr,0, -);$val 2=$mem -Get' Key2 '); Echo"Get key2 value:"; Print_r ($val 2); Echo"
"
;//Delete data$mem -Delete' Key1 ');$val=$mem -Get' Key1 '); Echo"Get key1 value:".$val."
"
;//Clear All data$mem -Flush ();$val 2=$mem -Get' Key2 '); Echo"Get key2 value:"; Print_r ($val 2); Echo"
"
;//Close connection$mem -Close ();?>
    1. Output
valueisvaluevalueisvaluevalue: Array ( [0] => aaa [1] => bbb [2] => ccc [3valuevalue:

Copyright Notice: Knowledge is taken to the people, to the people! Welcome reprint, Reprint please attach this article link, not regularly updated articles!

The above introduces the PHP memcache single case, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.