Skip to content

Commit fca2cd4

Browse files
author
Andrei Zmievski
committed
Merge branch 'master' of [email protected]:andreiz/php-memcached
2 parents 3b228f9 + f627ca6 commit fca2cd4

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

memcached-api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function get( $key, &$cas_token = null, $cache_cb = null ) {}
7979

8080
public function getByKey( $server_key, $key, $cache_cb = null ) {}
8181

82-
public function getMulti( array $keys, &$cas_tokens = null ) {}
82+
public function getMulti( array $keys, &$cas_tokens = null, $preserve_order = false ) {}
8383

84-
public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null ) {}
84+
public function getMultiByKey( $server_key, array $keys, &$cas_tokens = null, $preserve_order = false ) {}
8585

8686
public function getDelayed( array $keys, $with_cas = null, $value_cb = null ) {}
8787

php_memcached.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,28 +490,30 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
490490
zval *cas_tokens = NULL;
491491
uint64_t orig_cas_flag;
492492
zval *value;
493+
zend_bool preserve_order = 0;
493494
int i = 0;
494495
memcached_result_st result;
495496
memcached_return status = MEMCACHED_SUCCESS;
496497
MEMC_METHOD_INIT_VARS;
497498

498499
if (by_key) {
499-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|z", &server_key,
500-
&server_key_len, &keys, &cas_tokens) == FAILURE) {
500+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|zb", &server_key,
501+
&server_key_len, &keys, &cas_tokens,&preserve_order) == FAILURE) {
501502
return;
502503
}
503504
} else {
504-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &keys, &cas_tokens) == FAILURE) {
505+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb", &keys, &cas_tokens, &preserve_order) == FAILURE) {
505506
return;
506507
}
507508
}
508-
509+
509510
MEMC_METHOD_FETCH_OBJECT;
510511
MEMC_G(rescode) = MEMCACHED_SUCCESS;
511512

512513
num_keys = zend_hash_num_elements(Z_ARRVAL_P(keys));
513514
mkeys = safe_emalloc(num_keys, sizeof(char *), 0);
514515
mkeys_len = safe_emalloc(num_keys, sizeof(size_t), 0);
516+
array_init(return_value);
515517

516518
/*
517519
* Create the array of keys for libmemcached. If none of the keys were valid
@@ -524,6 +526,9 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
524526
if (Z_TYPE_PP(entry) == IS_STRING && Z_STRLEN_PP(entry) > 0) {
525527
mkeys[i] = Z_STRVAL_PP(entry);
526528
mkeys_len[i] = Z_STRLEN_PP(entry);
529+
if(preserve_order) {
530+
add_assoc_null_ex(return_value, mkeys[i], mkeys_len[i]+1);
531+
}
527532
i++;
528533
}
529534
}
@@ -570,7 +575,7 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
570575
zval_dtor(cas_tokens);
571576
array_init(cas_tokens);
572577
}
573-
array_init(return_value);
578+
574579
status = MEMCACHED_SUCCESS;
575580
memcached_result_create(i_obj->memc, &result);
576581
while ((memcached_fetch_result(i_obj->memc, &result, &status)) != NULL) {
@@ -2445,12 +2450,14 @@ ZEND_END_ARG_INFO()
24452450
ZEND_BEGIN_ARG_INFO_EX(arginfo_getMulti, 0, 0, 1)
24462451
ZEND_ARG_ARRAY_INFO(0, keys, 0)
24472452
ZEND_ARG_INFO(1, cas_tokens)
2453+
ZEND_ARG_INFO(0, preserve_order)
24482454
ZEND_END_ARG_INFO()
24492455

24502456
ZEND_BEGIN_ARG_INFO_EX(arginfo_getMultiByKey, 0, 0, 2)
24512457
ZEND_ARG_INFO(0, server_key)
24522458
ZEND_ARG_ARRAY_INFO(0, keys, 0)
24532459
ZEND_ARG_INFO(1, cas_tokens)
2460+
ZEND_ARG_INFO(0, preserve_order)
24542461
ZEND_END_ARG_INFO()
24552462

24562463
ZEND_BEGIN_ARG_INFO_EX(arginfo_getDelayed, 0, 0, 1)

tests/multi_order.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Memcached check preserve_order in getMulti
3+
--SKIPIF--
4+
<?php if (!extension_loaded("memcached")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$m = new Memcached();
8+
$m->addServer('127.0.0.1', 11211, 1);
9+
$m->addServer('localhost', 11211, 1);
10+
11+
$data = array(
12+
'foo' => 'foo-data',
13+
'bar' => 'bar-data',
14+
'baz' => 'baz-data',
15+
'lol' => 'lol-data',
16+
'kek' => 'kek-data',
17+
);
18+
19+
//$m->setMulti($data, 3600);
20+
foreach ($data as $k => $v) {
21+
$m->set($k, $v, 3600);
22+
}
23+
24+
$null = null;
25+
$got = $m->getMulti(array_keys($data), $null, true);
26+
27+
foreach ($got as $k => $v) {
28+
echo "$k $v\n";
29+
}
30+
31+
?>
32+
--EXPECT--
33+
foo foo-data
34+
bar bar-data
35+
baz baz-data
36+
lol lol-data
37+
kek kek-data

0 commit comments

Comments
 (0)