long keys get truncated

chx - July 20, 2009 - 19:18
Project:Memcache API and Integration
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

memcache truncates longer than 250 keys. not good.

AttachmentSize
x.patch600 bytes

#2

justinrandell - August 5, 2009 - 18:27
Status:needs review» reviewed & tested by the community

yes, can we have this please? we hit a bug in the latest php module, where keys passed to memcache greater than 250 are causing php to segfault. that's a bug a in the C module, but passing anything longer than 250 is a bug in this module.

chx's patch looks good to me, and we're using it in production.

#3

justinrandell - August 5, 2009 - 18:39
Status:reviewed & tested by the community» needs work

woops, that patch should be:

<?php
 
return strlen(urlencode($full_key)) > 250 ? $prefix . $bin . '-' . md5($key) : urlencode($full_key);
?>

because the urlencode'd key can be longer than the straight full key.

#4

Swampcritter - September 2, 2009 - 13:48

Any idea on when this patch can be committed w/ justinrandell's modification? I have it deployed for a couple of smaller production sites and so far it has definitely fixed our memcache long key problem.

-- M

#5

ball.in.th - October 27, 2009 - 15:19

Hi,

Is there a particular reason why the $full_key has to be urlencode()? Does memcache support binary key? In fact, urlencoding could make the key a lot longer. For example, if the key is a string "http://drupal.org/สวัสดีดรูพัลด้วยภาษาไทยก็ยาวเกินแล้ว", urlencode it would make it become "http://drupal.org/%E0%B8%AA%E0%B8%A7%E0%B8%B1%E0%B8%AA%E0%B8%94%E0%B8%B5%E0%B8%94%E0%B8%A3%E0%B8%B9%E0%B8%9E%E0%B8%B1%E0%B8%A5%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%A0%E0%B8%B2%E0%B8%A9%E0%B8%B2%E0%B9%84%E0%B8%97%E0%B8%A2%E0%B8%81%E0%B9%87%E0%B8%A2%E0%B8%B2%E0%B8%A7%E0%B9%80%E0%B8%81%E0%B8%B4%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7" totaling 342 characters.

#6

ball.in.th - October 27, 2009 - 15:32
Status:needs work» active

Hi,

I've tested memcache with keys in utf8 and it worked fine. So, there's no need to urlencode the key at all.

<?php
$memcache
= new Memcache;
$memcache->connect("localhost", 11211);

$tmp_object = new stdClass;
$tmp_object->str_attr = "test";
$tmp_object->int_attr = 123;

$key = "blahชุมชนคอบอลอันดับ 1";
$memcache->set($key, $tmp_object, false, 10);

echo
"Data from the cache:<br />\n";
var_dump($memcache->get($key));
?>

#7

drewish - December 4, 2009 - 19:14

subscribing

 
 

Drupal is a registered trademark of Dries Buytaert.