|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-12-29 09:06 UTC] stuart at gentoo dot org
Description:
------------
memcache::get() in memcache-2.0.0 returns FALSE on error. This makes it impossible to retrieve the value FALSE if stored in memcache, because it's not possible to tell a genuine error apart from the value FALSE having been returned.
If memcache::get() returned NULL on error, this would solve the problem. The patch pasted below works nicely locally.
Best regards,
Stu
Reproduce code:
---------------
diff -u --recursive memcache-2.0.0/memcache.c memcache-2.0.0-patched/memcache.c
--- memcache-2.0.0/memcache.c 2005-12-21 18:21:55.000000000 +0000
+++ memcache-2.0.0-patched/memcache.c 2005-12-29 12:15:38.000000000 +0000
@@ -1706,17 +1706,17 @@
}
if (!mmc_get_pool(mmc_object, &pool TSRMLS_CC) || !pool->num_servers) {
- RETURN_FALSE;
+ RETURN_NULL();
}
if (Z_TYPE_P(key) != IS_ARRAY) {
if (mmc_exec_retrieval_cmd(pool, key, &return_value TSRMLS_CC) < 0) {
- RETURN_FALSE;
+ RETURN_NULL();
}
}
else {
if (mmc_exec_retrieval_cmd_multi(pool, key, &return_value TSRMLS_CC) < 0) {
- RETURN_FALSE;
+ RETURN_NULL();
}
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 01:00:02 2025 UTC |
An alternative solution is to modify the memcache_get function to take a third parameters (reference) where the value will be stored. I've implemented it and it works nicely, now i'm able to store NULL and FALSE values. Example usage code: if (memcache_get($m, $key, $val)) { print "Got it: $val\n"; } else { print "Not found :-(\n"; } If someone is interested i can post a patch for memcache-2.0.4For the users who need to separate FALSE, NULL and not-found/error, it can be implemented in userspace by always serializing the value before calling Memcache::set() class ExtendedMemcache extends Memcache { function get($key) { if (!($buffer = parent::get($key))) return false; return unserialize($buffer); } function getInto($key, &$value) { if (!($buffer = parent::get($key))) return false; return $value = unserialize($buffer); } function set($key, $value) { return parent::set($key, serialize($value)); } } As to separating not-found from hard errors, cache clients should treat errors as if the key wasn't non-found and fall back to secondary (persistent, database, ..) storage anyway, with error reporting performed internally through the regular trigger_error(). Closing the bugreport. //Mikael