Fix empty memcached value exception bug.

pylibmc would produce non-error exceptions because the memcached value
pointer would be NULL, while the return code would be zero.
This commit is contained in:
lericson 2009-10-31 11:22:18 +01:00
parent f5b756deb8
commit 343286a34b
2 changed files with 10 additions and 3 deletions

View File

@ -195,9 +195,10 @@ static PyObject *PylibMC_Client_get(PylibMC_Client *self, PyObject *arg) {
PyObject *r = _PylibMC_parse_memcached_value(mc_val, val_size, flags); PyObject *r = _PylibMC_parse_memcached_value(mc_val, val_size, flags);
free(mc_val); free(mc_val);
return r; return r;
} } else if (error == MEMCACHED_SUCCESS) {
/* This happens for empty values, and so we fake an empty string. */
if (error == MEMCACHED_NOTFOUND) { return PyString_FromStringAndSize("", 0);
} else if (error == MEMCACHED_NOTFOUND) {
/* Since python-memcache returns None when the key doesn't exist, /* Since python-memcache returns None when the key doesn't exist,
* so shall we. */ * so shall we. */
Py_RETURN_NONE; Py_RETURN_NONE;

View File

@ -14,6 +14,12 @@ True
>>> c.get("test_key") >>> c.get("test_key")
>>> >>>
We should handle empty values just nicely.
>>> c.set("foo", "")
True
>>> c.get("foo")
''
Now this section is because most other implementations ignore zero-keys. Now this section is because most other implementations ignore zero-keys.
>>> c.get("") >>> c.get("")
>>> c.set("", "hi") >>> c.set("", "hi")