The implementation code that fetches the memcache value and returns it in key order

  • 2020-05-07 19:25:04
  • OfStack

Get the following 15 values of ID in batches through the getMulti function of memcached.
31639,33878,177410,9735,589,12076,25953,22447,15368,15358,33853,26658,26659,12477,15366

$md- > getMulti($arr_id);
Return 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,

It is correct to return when there are 1 memcache, but it is impossible to return in order when there are more than 11 memcache.

Memcached::GET_PRESERVE_ORDER is needed 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,

If there are no hit variables, then $cas works. $cas returns the hit variable, iterates through $cas to fetch the hit variable composition data, then compares the array_diff function with $arr_id, and then goes to 11 to set.

Related articles: