Memcache implementation code to get Memcache values in bulk and return in order of key

Source: Internet
Author: User
The values of the following 15 IDs are obtained in bulk by Memcached's Getmulti function.
31639,33878,177410,9735,589,12076,25953,22447,15368,15358,33853,26658,26659,12477,15366
$MD->getmulti ($arr _id);
Order of Return:
line_31639,line_33878,line_177410,line_9735,line_589,line_12076,line_25953,line_22447,line_15368,line_15358, line_33853,line_26658,line_26659,line_12477,line_15366,
A memcache is returned correctly when there are multiple memcache that cannot be returned sequentially.
You need to use Memcached::get_preserve_order to return data sequentially:
$arrs = $mem->getmulti ($arr _id, $cas, Memcached::get_preserve_order);
Order of Return:
line_31639,line_33878,line_9735,line_589,line_22447,line_15358,line_33853,line_26658,line_177410,line_12076, line_25953,line_15368,line_26659,line_12477,line_15366,
In this case, if there are no hit variables, then $cas will play a role. $cas return a hit variable, traverse $cas to take out the hit variable to make up the data, then compare the Array_diff function with the $arr_id to remove the difference, then go to one by one settings.

The above describes the memcache batch to get Memcache value and the order of the key to return the implementation code, including the memcache aspect 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.