Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #77 from myYearbook/1.2.2-behaviors

MEMCACHED_BEHAVIOR_TCP_KEEPALIVE and MEMCACHED_CALLBACK_PREFIX_KEY
  • Loading branch information...
commit e1de2954408388969d0b77bab1d490cdcfa0d216 2 parents def0eab + 96ac5b6
@lericson authored
View
48 _pylibmcmodule.c
@@ -1648,12 +1648,12 @@ static PyObject *PylibMC_Client_get_behaviors(PylibMC_Client *self) {
static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *self,
PyObject *behaviors) {
PylibMC_Behavior *b;
+ PyObject *py_v;
+ uint64_t v;
+ memcached_return r;
+ char *key;
for (b = PylibMC_behaviors; b->name != NULL; b++) {
- PyObject *py_v;
- uint64_t v;
- memcached_return r;
-
if (!PyMapping_HasKeyString(behaviors, b->name)) {
continue;
} else if ((py_v = PyMapping_GetItemString(behaviors, b->name)) == NULL) {
@@ -1675,6 +1675,28 @@ static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *self,
}
}
+ for (b = PylibMC_callbacks; b->name != NULL; b++) {
+ if (!PyMapping_HasKeyString(behaviors, b->name)) {
+ continue;
+ } else if ((py_v = PyMapping_GetItemString(behaviors, b->name)) == NULL) {
+ goto error;
+ }
+
+ key = PyString_AS_STRING(py_v);
+
+ r = memcached_callback_set(self->mc, b->flag, key);
+
+ if (r == MEMCACHED_BAD_KEY_PROVIDED) {
+ PyErr_Format(PyExc_ValueError, "bad key provided: %s", key);
+ goto error;
+ } else if (r != MEMCACHED_SUCCESS) {
+ PyErr_Format(PylibMCExc_MemcachedError,
+ "memcached_callback_set returned %d for "
+ "callback '%.32s' = %.32s", r, b->name, key);
+ goto error;
+ }
+ }
+
Py_RETURN_NONE;
error:
return NULL;
@@ -2072,7 +2094,7 @@ static void _make_excs(PyObject *module) {
}
static void _make_behavior_consts(PyObject *mod) {
- PyObject *behavior_names;
+ PyObject *names;
PylibMC_Behavior *b;
char name[128];
@@ -2087,13 +2109,23 @@ static void _make_behavior_consts(PyObject *mod) {
PyModule_AddIntConstant(mod, name, b->flag);
}
- behavior_names = PyList_New(0);
+ names = PyList_New(0);
+
+ for (b = PylibMC_callbacks; b->name != NULL; b++) {
+ sprintf(name, "callback_%s", b->name);
+ PyModule_AddIntConstant(mod, name, b->flag);
+ PyList_Append(names, PyString_FromString(b->name));
+ }
+
+ PyModule_AddObject(mod, "all_callbacks", names);
+
+ names = PyList_New(0);
for (b = PylibMC_behaviors; b->name != NULL; b++) {
- PyList_Append(behavior_names, PyString_FromString(b->name));
+ PyList_Append(names, PyString_FromString(b->name));
}
- PyModule_AddObject(mod, "all_behaviors", behavior_names);
+ PyModule_AddObject(mod, "all_behaviors", names);
}
static PyMethodDef PylibMC_functions[] = {
View
5 _pylibmcmodule.h
@@ -176,6 +176,7 @@ typedef struct {
static PylibMC_Behavior PylibMC_behaviors[] = {
{ MEMCACHED_BEHAVIOR_NO_BLOCK, "no_block" },
{ MEMCACHED_BEHAVIOR_TCP_NODELAY, "tcp_nodelay" },
+ { MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, "tcp_keepalive" },
{ MEMCACHED_BEHAVIOR_HASH, "hash" },
{ MEMCACHED_BEHAVIOR_KETAMA_HASH, "ketama_hash" },
{ MEMCACHED_BEHAVIOR_KETAMA, "ketama" },
@@ -212,6 +213,10 @@ static PylibMC_Behavior PylibMC_behaviors[] = {
{ 0, NULL }
};
+static PylibMC_Behavior PylibMC_callbacks[] = {
+ { MEMCACHED_CALLBACK_PREFIX_KEY, "prefix_key" },
+ { 0, NULL }
+};
static PylibMC_Behavior PylibMC_hashers[] = {
{ MEMCACHED_HASH_DEFAULT, "default" },
{ MEMCACHED_HASH_MD5, "md5" },
View
3  pylibmc/client.py
@@ -3,9 +3,10 @@
import _pylibmc
from .consts import (hashers, distributions, all_behaviors,
hashers_rvs, distributions_rvs,
- BehaviorDict)
+ all_callbacks, BehaviorDict)
_all_behaviors_set = set(all_behaviors)
+_all_behaviors_set.update(set(all_callbacks))
server_type_map = {"tcp": _pylibmc.server_type_tcp,
"udp": _pylibmc.server_type_udp,
View
1  pylibmc/consts.py
@@ -14,6 +14,7 @@
setattr(modpkg, name, exc)
all_behaviors = _pylibmc.all_behaviors
+all_callbacks = _pylibmc.all_callbacks
hashers, hashers_rvs = {}, {}
distributions, distributions_rvs = {}, {}
# Not the prettiest way of doing things, but works well.
Please sign in to comment.
Something went wrong with that request. Please try again.