Add memcached_clone support.
This commit is contained in:
parent
e8817b6617
commit
bc40569572
@ -745,6 +745,21 @@ static PyObject *PylibMC_Client_disconnect_all(PylibMC_Client *self) {
|
|||||||
memcached_quit(self->mc);
|
memcached_quit(self->mc);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *PylibMC_Client_clone(PylibMC_Client *self) {
|
||||||
|
PylibMC_Client *new_self;
|
||||||
|
|
||||||
|
/* XXX Is it really wise to short-circuit like this? I don't see a problem
|
||||||
|
* with it. */
|
||||||
|
new_self = (PylibMC_Client *)self->ob_type->tp_new(self->ob_type, NULL, NULL);
|
||||||
|
if (new_self == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memset(new_self->mc, 0, sizeof(memcached_st));
|
||||||
|
new_self->mc = memcached_clone(new_self->mc, self->mc);
|
||||||
|
|
||||||
|
return (PyObject *)new_self;
|
||||||
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static PyObject *PylibMC_ErrFromMemcached(PylibMC_Client *self, const char *what,
|
static PyObject *PylibMC_ErrFromMemcached(PylibMC_Client *self, const char *what,
|
||||||
|
@ -149,6 +149,7 @@ static PyObject *PylibMC_Client_get_behaviors(PylibMC_Client *);
|
|||||||
static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *, PyObject *);
|
static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *, PyObject *);
|
||||||
static PyObject *PylibMC_Client_flush_all(PylibMC_Client *, PyObject *, PyObject *);
|
static PyObject *PylibMC_Client_flush_all(PylibMC_Client *, PyObject *, PyObject *);
|
||||||
static PyObject *PylibMC_Client_disconnect_all(PylibMC_Client *);
|
static PyObject *PylibMC_Client_disconnect_all(PylibMC_Client *);
|
||||||
|
static PyObject *PylibMC_Client_clone(PylibMC_Client *);
|
||||||
static PyObject *PylibMC_ErrFromMemcached(PylibMC_Client *, const char *,
|
static PyObject *PylibMC_ErrFromMemcached(PylibMC_Client *, const char *,
|
||||||
memcached_return);
|
memcached_return);
|
||||||
static PyObject *_PylibMC_Unpickle(const char *, size_t);
|
static PyObject *_PylibMC_Unpickle(const char *, size_t);
|
||||||
@ -191,6 +192,9 @@ static PyMethodDef PylibMC_ClientType_methods[] = {
|
|||||||
METH_VARARGS|METH_KEYWORDS, "Flush all data on all servers."},
|
METH_VARARGS|METH_KEYWORDS, "Flush all data on all servers."},
|
||||||
{"disconnect_all", (PyCFunction)PylibMC_Client_disconnect_all, METH_NOARGS,
|
{"disconnect_all", (PyCFunction)PylibMC_Client_disconnect_all, METH_NOARGS,
|
||||||
"Disconnect from all servers and reset own state."},
|
"Disconnect from all servers and reset own state."},
|
||||||
|
{"clone", (PyCFunction)PylibMC_Client_clone, METH_NOARGS,
|
||||||
|
"Clone this client entirely such that it is safe to access from "
|
||||||
|
"another thread. This creates a new connection."},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
11
tests.py
11
tests.py
@ -116,6 +116,17 @@ True
|
|||||||
>>> c.get("tengil").bar == bla.bar
|
>>> c.get("tengil").bar == bla.bar
|
||||||
True
|
True
|
||||||
|
|
||||||
|
Cloning (ethically, I don't know about it.)
|
||||||
|
>>> c is not c.clone()
|
||||||
|
True
|
||||||
|
>>> c2 = c.clone()
|
||||||
|
>>> c.set("test", "hello")
|
||||||
|
True
|
||||||
|
>>> c2.get("test")
|
||||||
|
'hello'
|
||||||
|
>>> c2.delete("test")
|
||||||
|
True
|
||||||
|
>>> del c2
|
||||||
|
|
||||||
Behaviors.
|
Behaviors.
|
||||||
>>> c.set_behaviors({"tcp_nodelay": True, "hash": 6})
|
>>> c.set_behaviors({"tcp_nodelay": True, "hash": 6})
|
||||||
|
Reference in New Issue
Block a user