From dbb6ca2255548c7237a23ba66941fd0e6d2a8c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kowalak?= Date: Fri, 13 Apr 2012 15:49:38 +0300 Subject: [PATCH 1/2] gets: Return (None, None) when key does not exist This changes behavior of gets command to be compatible with get command. --- _pylibmcmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pylibmcmodule.c b/_pylibmcmodule.c index 3a6a803..47d4fba 100644 --- a/_pylibmcmodule.c +++ b/_pylibmcmodule.c @@ -518,7 +518,7 @@ static PyObject *PylibMC_Client_gets(PylibMC_Client *self, PyObject *arg) { ret = NULL; PyErr_SetString(PyExc_RuntimeError, "fetch not done"); } - } else if (rc == MEMCACHED_END) { + } else if (rc == MEMCACHED_END || rc == MEMCACHED_NOTFOUND) { /* Key not found => (None, None) */ ret = Py_BuildValue("(OO)", Py_None, Py_None); } else { From 5cfc5e1a7d2eabdfe9b725f8acb3f2102577bd98 Mon Sep 17 00:00:00 2001 From: Pawel Kowalak Date: Wed, 18 Apr 2012 10:38:15 +0300 Subject: [PATCH 2/2] Test for changed gets() return value Refs #87 --- tests/doctests.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/doctests.txt b/tests/doctests.txt index 7e9e2af..c13970a 100644 --- a/tests/doctests.txt +++ b/tests/doctests.txt @@ -261,3 +261,9 @@ Test server/client max length Traceback (most recent call last): ... ValueError: key too long, max is 250 + +Gets should return (None, None) for non-existing keys +>>> c = make_test_client(_pylibmc.client, binary=True) +>>> c.set_behaviors({'cas': True}) +>>> c.gets('non_existing_key') +(None, None)