Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Add set_timeout and get_timeout methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipin Dmitriy committed Jan 16, 2013
1 parent 931f768 commit 538408f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
34 changes: 34 additions & 0 deletions python/umemcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,38 @@ PyObject *Client_flush_all(PyClient *self, PyObject *args)
Py_RETURN_NONE;
}

PyObject *Client_set_timeout(PyClient *self, PyObject *args)
{

PyObject *timeout;

if (!PyArg_ParseTuple (args, "O", &timeout))
{
return NULL;
}

PyObject *method = PyString_FromString("settimeout");
PyObject *res = PyObject_CallMethodObjArgs(self->sock, method, timeout, NULL);

PRINTMARK();

Py_DECREF(method);

return res;
}

PyObject *Client_get_timeout(PyClient *self, PyObject *args)
{

PyObject *method = PyString_FromString("gettimeout");
PyObject *res = PyObject_CallMethodObjArgs(self->sock, method, NULL);

PRINTMARK();

Py_DECREF(method);

return res;
}



Expand Down Expand Up @@ -1078,6 +1110,8 @@ static PyMethodDef Client_methods[] = {
{"version", (PyCFunction) Client_version, METH_NOARGS, "def version(self)"},
{"stats", (PyCFunction) Client_stats, METH_NOARGS, "def stats(self)"},
{"flush_all", (PyCFunction) Client_flush_all, METH_VARARGS, "def flush_all(self, expiration = 0, async = False)"},
{"set_timeout", (PyCFunction) Client_set_timeout, METH_VARARGS, "def set_timeout(self, value)"},
{"get_timeout", (PyCFunction) Client_get_timeout, METH_NOARGS, "def get_timeout(self)"},
{"begin_pipeline", (PyCFunction) Client_begin_pipeline, METH_NOARGS, "def begin_pipeline(self)"},
{"abort_pipeline", (PyCFunction) Client_abort_pipeline, METH_NOARGS, "def abort_pipeline(self)"},
{"finish_pipeline", (PyCFunction) Client_finish_pipeline, METH_NOARGS, "def finish_pipeline(self)"},
Expand Down
6 changes: 6 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ def testReadOnly(self):
for attr in ('sock', 'host', 'port'):
self.assertRaises(TypeError, setattr, c, attr, 'booo')

def testTimeout(self):
timeout = 1.5
c = Client(MEMCACHED_ADDRESS)
c.set_timeout(timeout)
self.assertAlmostEqual(timeout, c.get_timeout())

def testPipeline(self):
c1 = Client(MEMCACHED_ADDRESS)
c2 = Client(MEMCACHED_ADDRESS)
Expand Down

0 comments on commit 538408f

Please sign in to comment.