diff --git a/_pylibmcmodule.c b/_pylibmcmodule.c index 1f812e4..674d97f 100644 --- a/_pylibmcmodule.c +++ b/_pylibmcmodule.c @@ -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); free(mc_val); return r; - } - - if (error == MEMCACHED_NOTFOUND) { + } else if (error == MEMCACHED_SUCCESS) { + /* This happens for empty values, and so we fake an empty string. */ + return PyString_FromStringAndSize("", 0); + } else if (error == MEMCACHED_NOTFOUND) { /* Since python-memcache returns None when the key doesn't exist, * so shall we. */ Py_RETURN_NONE; diff --git a/tests.py b/tests.py index 96e60ca..a545900 100644 --- a/tests.py +++ b/tests.py @@ -14,6 +14,12 @@ True >>> 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. >>> c.get("") >>> c.set("", "hi")