Add support for the binary protocol.
Also removed two behaviors from public exposure as they're better off controlled by `_pylibmc`. (USE_UDP and BINARY_PROTOCOL.)
This commit is contained in:
parent
279544a468
commit
16e964e571
@ -57,20 +57,20 @@ static void PylibMC_ClientType_dealloc(PylibMC_Client *self) {
|
|||||||
|
|
||||||
static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args,
|
static int PylibMC_Client_init(PylibMC_Client *self, PyObject *args,
|
||||||
PyObject *kwds) {
|
PyObject *kwds) {
|
||||||
PyObject *srv_list, *srv_list_it, *c_srv;
|
PyObject *srvs, *srvs_it, *c_srv;
|
||||||
unsigned char set_stype = 0;
|
unsigned char set_stype = 0, bin = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O", &srv_list)) {
|
static char *kws[] = { "servers", "binary", NULL };
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|b", kws, &srvs, &bin)) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else if ((srvs_it = PyObject_GetIter(srvs)) == NULL) {
|
||||||
kwds = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((srv_list_it = PyObject_GetIter(srv_list)) == NULL) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c_srv = PyIter_Next(srv_list_it)) != NULL) {
|
memcached_behavior_set(self->mc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, bin);
|
||||||
|
|
||||||
|
while ((c_srv = PyIter_Next(srvs_it)) != NULL) {
|
||||||
unsigned char stype;
|
unsigned char stype;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
unsigned short int port;
|
unsigned short int port;
|
||||||
@ -137,10 +137,10 @@ it_error:
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_DECREF(srv_list_it);
|
Py_DECREF(srvs_it);
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
Py_DECREF(srv_list_it);
|
Py_DECREF(srvs_it);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +94,9 @@ static PylibMC_Behavior PylibMC_behaviors[] = {
|
|||||||
{ MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "retry_timeout" },
|
{ MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, "retry_timeout" },
|
||||||
{ MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "ketama_weighted" },
|
{ MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, "ketama_weighted" },
|
||||||
{ MEMCACHED_BEHAVIOR_KETAMA_HASH, "ketama_hash" },
|
{ MEMCACHED_BEHAVIOR_KETAMA_HASH, "ketama_hash" },
|
||||||
{ MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, "binary_protocol" },
|
|
||||||
{ MEMCACHED_BEHAVIOR_SND_TIMEOUT, "snd_timeout" },
|
{ MEMCACHED_BEHAVIOR_SND_TIMEOUT, "snd_timeout" },
|
||||||
{ MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "rcv_timeout" },
|
{ MEMCACHED_BEHAVIOR_RCV_TIMEOUT, "rcv_timeout" },
|
||||||
{ MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "server_failure_limit" },
|
{ MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, "server_failure_limit" },
|
||||||
{ MEMCACHED_BEHAVIOR_USE_UDP, "udp" },
|
|
||||||
{ MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "_io_msg_watermark" },
|
{ MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, "_io_msg_watermark" },
|
||||||
{ MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "_io_bytes_watermark" },
|
{ MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, "_io_bytes_watermark" },
|
||||||
{ MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, "_io_key_prefetch" },
|
{ MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, "_io_key_prefetch" },
|
||||||
|
@ -54,12 +54,14 @@ class BehaviorDict(dict):
|
|||||||
self.client.set_behaviors(self.copy())
|
self.client.set_behaviors(self.copy())
|
||||||
|
|
||||||
class Client(_pylibmc.client):
|
class Client(_pylibmc.client):
|
||||||
def __init__(self, servers, *args, **kwds):
|
def __init__(self, servers, binary=False):
|
||||||
"""Initialize a memcached client instance.
|
"""Initialize a memcached client instance.
|
||||||
|
|
||||||
This connects to the servers in *servers*, which will default to being
|
This connects to the servers in *servers*, which will default to being
|
||||||
TCP servers. If it looks like a filesystem path, a UNIX socket. If
|
TCP servers. If it looks like a filesystem path, a UNIX socket. If
|
||||||
prefixed with `udp:`, a UDP connection.
|
prefixed with `udp:`, a UDP connection.
|
||||||
|
|
||||||
|
If *binary* is True, the binary memcached protocol is used.
|
||||||
"""
|
"""
|
||||||
addr_tups = []
|
addr_tups = []
|
||||||
for server in servers:
|
for server in servers:
|
||||||
@ -81,7 +83,7 @@ class Client(_pylibmc.client):
|
|||||||
else:
|
else:
|
||||||
stype = _pylibmc.server_type_tcp
|
stype = _pylibmc.server_type_tcp
|
||||||
addr_tups.append((stype, addr, port))
|
addr_tups.append((stype, addr, port))
|
||||||
super(Client, self).__init__(addr_tups)
|
super(Client, self).__init__(servers=addr_tups, binary=binary)
|
||||||
|
|
||||||
def get_behaviors(self):
|
def get_behaviors(self):
|
||||||
"""Gets the behaviors from the underlying C client instance.
|
"""Gets the behaviors from the underlying C client instance.
|
||||||
|
Reference in New Issue
Block a user