added uwsgi.cache_keys function api

This commit is contained in:
Unbit
2013-08-23 10:43:13 +02:00
parent da13562890
commit d4e90f5215
3 changed files with 54 additions and 0 deletions
+30
View File
@@ -3109,6 +3109,35 @@ PyObject *py_uwsgi_cache_num(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_cache_keys(PyObject * self, PyObject * args) {
char *cache = NULL;
struct uwsgi_cache_item *uci = NULL;
uint64_t pos = 0;
if (!PyArg_ParseTuple(args, "|s:cache_keys", &cache)) {
return NULL;
}
struct uwsgi_cache *uc = uwsgi_cache_by_name(cache);
if (!uc) {
return PyErr_Format(PyExc_ValueError, "no local uWSGI cache available");
}
PyObject *l = PyList_New(0);
uwsgi_rlock(uc->lock);
for(;;) {
uci = uwsgi_cache_keys(uc, &pos, &uci);
if (!uci) break;
PyObject *ci = PyString_FromStringAndSize(uci->key, uci->keysize);
PyList_Append(l, ci);
Py_DECREF(ci);
}
uwsgi_rwunlock(uc->lock);
return l;
}
static PyMethodDef uwsgi_cache_methods[] = {
{"cache_get", py_uwsgi_cache_get, METH_VARARGS, ""},
{"cache_set", py_uwsgi_cache_set, METH_VARARGS, ""},
@@ -3121,6 +3150,7 @@ static PyMethodDef uwsgi_cache_methods[] = {
{"cache_mul", py_uwsgi_cache_mul, METH_VARARGS, ""},
{"cache_div", py_uwsgi_cache_div, METH_VARARGS, ""},
{"cache_num", py_uwsgi_cache_num, METH_VARARGS, ""},
{"cache_keys", py_uwsgi_cache_keys, METH_VARARGS, ""},
{NULL, NULL},
};