Set and add methods for PHPmemcached Extension

Source: Internet
Author: User
{Code...} Does the use of set and add need to be intentionally differentiated? Isn't it possible for me to use set all?
$ SQL = "SELECT * FROM typecho_contents WHERE cid = '1'"; $ memc_key = md5 ($ SQL); $ memc = new Memcached (); $ memc-> addServer ('2017. 0.0.1 ', '000000'); $ memc_res = $ memc-> get ($ memc_key); if ($ memc_res) {echo $ memc_res ;} else {// obtain $ str $ memc_res = $ memc-> set (memc_key, $ str) from the database query. // If set is used, you should still use $ memc-> getResultCode () query the last error message. How can I use add ?}

Do I need to differentiate the use of set and add? Isn't that all I need to use set?

Reply content:
$ SQL = "SELECT * FROM typecho_contents WHERE cid = '1'"; $ memc_key = md5 ($ SQL); $ memc = new Memcached (); $ memc-> addServer ('2017. 0.0.1 ', '000000'); $ memc_res = $ memc-> get ($ memc_key); if ($ memc_res) {echo $ memc_res ;} else {// obtain $ str $ memc_res = $ memc-> set (memc_key, $ str) from the database query. // If set is used, you should still use $ memc-> getResultCode () query the last error message. How can I use add ?}

Do I need to differentiate the use of set and add? Isn't that all I need to use set?

Http://serverfault.com/questions/291681/add-vs-set-in-memcached
Simply put, if you don't care whether you have thiskeyYou can use it directly.setRight.

setAndaddThe most obvious difference is:
IfkeyYes already existssetIs to update the original data, andaddNo.

Set tends to update values, and add tends to add data groups.

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.