Edit report at https://bugs.php.net/bug.php?id=59990&edit=1

 ID:                 59990
 Comment by:         nate at frickenate dot com
 Reported by:        nate dot whittaker at gmail dot com
 Summary:            getMulti can return non-unique keys
 Status:             Open
 Type:               Bug
 Package:            memcached
 Operating System:   Mac OS X
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Confirmed. Even without the Memcached::GET_PRESERVE_ORDER option, using 
getMulti() with binary protocol enabled results in some kind of parsing problem 
that winds up making some indexes returned in the array not equal to the actual 
key requested.

I know this sounds crazy, but if I get the key "helloworld" from memcached, 
doing a var_dump() of the result shows "helloworld" index in the array - 
however, array_key_exists("helloworld", $result) fails. Somehow the index as 
seen by the eye is not the same as the actual index stored by php.

It's a little messed up - php does not allow for multiple entries of the same 
index in an array, unless memcached package somehow bypasses php's protections. 
I would guess that there is a NULL (byte 0) character in the string somewhere, 
but this is not the case. If I dump the serialize() or json_encode() of the 
array, a NULL character is nowhere to be seen.

Thanks to the other Nate (strange coincidence) for bringing the binary protocol 
to light. I couldn't track down the cause of this behaviour myself, however 
disabling binary protocol in the client does indeed solve the problem.


Previous Comments:
------------------------------------------------------------------------
[2011-10-04 18:40:27] nate dot whittaker at gmail dot com

Description:
------------
When the binary protocol is enabled and when passing the 3rd 
parameter, Memcached::GET_PRESERVE_ORDER, to getMulti(), the 
resulting array contains non-unique keys.

In other words, each key is represented twice in the result. 
One is set to null and the other is set to the value of 
whatever was stored in memcached.

getResultMessage() shows "SUCCESS".

I'm actually on php 5.3.8

Reproduce code:
---------------
$MC = new Memcached;
$MC->setOption(Memcached::OPT_BINARY_PROTOCOL, true); // Removing this causes 
the code to work, but at the 'expense' of reverting to the ASCII protocol
$MC->addServer('localhost', 11211);

$KeyList = Array (
     'key1'
    ,'key2'
    ,'key3'
    ,'key4'
);

$Test = Array();
foreach ($KeyList as $k) {
    $Test[$k] = 'stored value for '.$k;
}

// This block uses the *Multi() functions
$MC->setMulti($Test, 3600);

sleep(1);
$null = null;
$theList = $MC->getMulti($KeyList, $null, Memcached::GET_PRESERVE_ORDER);

var_dump($theList);

Expected result:
----------------
var_dump should shows:

array
     'key1' => 'stored value for key1'
     'key2' => 'stored value for key2'
     'key3' => 'stored value for key3'
     'key4' => 'stored value for key4'

Actual result:
--------------
var_dump shows:

array
     'key1' => null
     'key2' => null
     'key3' => null
     'key4' => null
     'key1' => 'stored value for key1'
     'key2' => 'stored value for key2'
     'key3' => 'stored value for key3'
     'key4' => 'stored value for key4'


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=59990&edit=1

Reply via email to