Home  >  Article  >  Backend Development  >  memcache implementation code to obtain memcache values ​​in batches and return them in key order

memcache implementation code to obtain memcache values ​​in batches and return them in key order

WBOY
WBOYOriginal
2016-07-29 08:45:37995browse

Use the getMulti function of memcached to obtain the values ​​of the following 15 IDs in batches.
31639,33878,177410,9735,589,12076,25953,22447,15368,15358,33853,26658,26659,12477,15366
$md->getMulti($arr_id);
Return The order:
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,
When a memcache is used, the return value is Correct, when there are multiple memcaches, they cannot correspond one to one. Return in order.
You need to use Memcached::GET_PRESERVE_ORDER to return data in order:
$arrs = $mem->getMulti($arr_id, $cas, Memcached::GET_PRESERVE_ORDER);
Return order:
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,
Among them, if there are variables that are not hit, then $cas will play a role. $cas returns the hit variable, traverses $cas to retrieve the hit variable composition data, and then uses the array_diff function to compare it with $arr_id to get the difference, and then set it one by one.

The above introduces the implementation code for memcache to obtain memcache values ​​in batches and return them in key order, including memcache content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn