Welcome to moecache’s documentation!¶
Contents:
moecache Module¶
A memcached client with a different shading strategy.
Usage example:
import moecache
with moecache.Client([("127.0.0.1", 11211), ("127.0.0.1", 11213)],
timeout=1, connect_timeout=5) as mc:
mc.set("some_key", "Some value")
value = mc.get("some_key")
mc.delete("another_key")
Note
If the value to store is of type str, the entry is binary compatible
with EnyimMemcached; otherwise, the value will be “pickled” with protocol
version 2 and can only be read by moecache.
-
class
moecache.Client(servers[, timeout[, connect_timeout]])¶ Creates an object to hold a moecache session. The object is also a context manager, which automatically closes the sockets when the control leaves the
withstatement.serverscan be a single server, or a list of servers, where each server is a(host, port)tuple, same as asocketAF_INET address.If
timeoutis not specified, socket operations may block forever. Ifconnect_timeoutis not specified, thetimeoutsetting will also be applied to the socketconnect()operations.-
set(key, val, exptime=0)¶ Sets a key to a value with an optional expire time in seconds (0 means don’t auto-expire).
A valid
keyis a string with a minimal length of 1 and a maximal length of 250, and each character is an ASCII graph character (printable except spaces).A valid
exptimeis a non-negative integer.If any of these arguments is invalid,
ValidationExceptionwill be raise. May also raiseClientExceptionand socket errors.
-
get(key)¶ Gets a single value. Returns
Noneif the key does not exist.Raises
ValidationExceptionifkeyis invalid. May also raiseClientExceptionand socket errors.
-
delete(key)¶ Deletes a key/value pair.
Raises
ValidationExceptionifkeyis invalid. May also raiseClientExceptionand socket errors.Note
The postcondition of this operation is that the entry no longer exists, so if the key does not exists at the first place, nothing happens and the function returns without error.
-
stats([additional_args])¶ Aggregates the stats from all the servers.
additional_argsis a byte string being passed verbatim to the servers. See the memcached wiki for details or the spec for even more details.Raises
ClientExceptionand socket errors.
-
close()¶ Closes any opened socket.
Sockets are automatically closed when the
Clientobject gets out of the context.Raises socket errors.
-
-
exception
moecache.ClientException(msg[, item])¶ Raised when memcached does something we don’t expect, or the memcached deployment is not compatible with moecache.
Note
This does not include socket errors.
-
exception
moecache.ValidationException(msg, item)¶ Bases:
moecache.ClientExceptionRaised when the user input is invalid to this library.