note 76524 added to function.Memcache-set
| From: | Sc00bz at osu1 dot php dot net | Date: | Thu, 19 Jul 2007 08:20:04 +0000 |
| Subject: | note 76524 added to function.Memcache-set | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128712@lists.php.net to get a copy of this message | ||
This is just two minor things about memcache that might not be perfectly clear, the limits on key
and data sizes and what happen to flags in the memcache protocol.
* There is a max key size of 250 anything bigger gets truncated. There is also a (1MB - 42 bytes)
limit on the data.
* In the memcache protocol there is a 16bit, 32bit in newer version, flag that you can set to
whatever you want because memcache doesn't do anything with the flags. The php api doesn't
let you get the flags because php uses the flags for php's own use such as
"MEMCACHE_COMPRESSED" and I decided to test if it was doing something because it
wasn't part of the memcache protocol.
<?php
$memcache = new Memcache();
$memcache->connect("127.0.0.1", 11211);
// Since memcache truncates the keys at 250 bytes both the get "250 a's" and
"251 a's" will find the key in the cache
echo "*** Truncate key test ***<br>";
echo "set 251: " . ($memcache->set(str_repeat("a", 251), "value",
0, 1) ? "t" : "f") . "<br>";
echo "get 249: " . (($ret = $memcache->get(str_repeat("a", 249))) !== false ?
"'$ret'" : "f") . "<br>";
echo "get 250: " . (($ret = $memcache->get(str_repeat("a", 250))) !== false ?
"'$ret'" : "f") . "<br>";
echo "get 251: " . (($ret = $memcache->get(str_repeat("a", 251))) !== false ?
"'$ret'" : "f") . "<br>";
echo "delete: " . ($memcache->delete(str_repeat("a", 250)) ? "t" :
"f") . "<br><br>";
echo "*** Compress value test ***<br>";
echo "set 1024*1024-42: " . ($memcache->set("test", str_repeat("a",
1024*1024-42), 0, 1) ? "t" : "f") . "<br>";
echo "set 1024*1024-41: " . ($memcache->set("test", str_repeat("a",
1024*1024-41), 0, 1) ? "t" : "f") . "<br>";
echo "set 1024*1024 compressed: " . ($memcache->set("test",
str_repeat("a", 1024*1024), MEMCACHE_COMPRESSED, 1) ? "t" : "f") .
"<br>";
echo "delete: " . ($memcache->delete("test") ? "t" : "f")
. "<br>";
$memcache->close();
?>
Output:
*** Truncate key test ***
set 251: t
get 249: f
get 250: 'value'
get 251: 'value'
delete: t
*** Compress value test ***
set 1024*1024-42: t
set 1024*1024-41: f
set 1024*1024 compressed: t
delete: t
----
Server IP: 64.71.164.2
Probable Submitter: 68.23.161.189
----
Manual Page -- http://www.php.net/manual/en/function.Memcache-set.php
Edit -- https://master.php.net/note/edit/76524
Del: integrated -- https://master.php.net/note/delete/76524/integrated
Del: useless -- https://master.php.net/note/delete/76524/useless
Del: bad code -- https://master.php.net/note/delete/76524/bad+code
Del: spam -- https://master.php.net/note/delete/76524/spam
Del: non-english -- https://master.php.net/note/delete/76524/non-english
Del: in docs -- https://master.php.net/note/delete/76524/in+docs
Del: other reasons-- https://master.php.net/note/delete/76524
Reject -- https://master.php.net/note/reject/76524
Search -- https://master.php.net/manage/user-notes.php