mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-04 12:41:38 +00:00
added uwsgi.cache_keys function api
This commit is contained in:
@@ -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},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user