diff options
author | John Anderson <sontek@gmail.com> | 2015-06-19 19:43:49 -0700 |
---|---|---|
committer | John Anderson <sontek@gmail.com> | 2015-06-19 19:43:49 -0700 |
commit | c475526677a9ed40edaf2f474f404b38166eb8d9 (patch) | |
tree | cc2e37be45aa0d835743588100b31b9c191a8f8b /pymemcache | |
parent | e67d4e379bd2c8e8d715d03aa7b10e66fed02188 (diff) | |
download | pymemcache-c475526677a9ed40edaf2f474f404b38166eb8d9.tar.gz |
Initial implementation of docs
Diffstat (limited to 'pymemcache')
-rw-r--r-- | pymemcache/client.py | 85 |
1 files changed, 17 insertions, 68 deletions
diff --git a/pymemcache/client.py b/pymemcache/client.py index 9262234..3a09639 100644 --- a/pymemcache/client.py +++ b/pymemcache/client.py @@ -12,61 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -A comprehensive, fast, pure-Python memcached client library. - -Basic Usage: ------------- - - from pymemcache.client import Client - - client = Client(('localhost', 11211)) - client.set('some_key', 'some_value') - result = client.get('some_key') - - -Serialization: --------------- - - import json - from pymemcache.client import Client - - def json_serializer(key, value): - if type(value) == str: - return value, 1 - return json.dumps(value), 2 - - def json_deserializer(key, value, flags): - if flags == 1: - return value - if flags == 2: - return json.loads(value) - raise Exception("Unknown serialization format") - - client = Client(('localhost', 11211), serializer=json_serializer, - deserializer=json_deserializer) - client.set('key', {'a':'b', 'c':'d'}) - result = client.get('key') - - -Best Practices: ---------------- - - - Always set the connect_timeout and timeout arguments in the constructor to - avoid blocking your process when memcached is slow. - - Use the "noreply" flag for a significant performance boost. The "noreply" - flag is enabled by default for "set", "add", "replace", "append", "prepend", - and "delete". It is disabled by default for "cas", "incr" and "decr". It - obviously doesn't apply to any get calls. - - Use get_many and gets_many whenever possible, as they result in less - round trip times for fetching multiple keys. - - Use the "ignore_exc" flag to treat memcache/network errors as cache misses - on calls to the get* methods. This prevents failures in memcache, or network - errors, from killing your web requests. Do not use this flag if you need to - know about errors from memcache, and make sure you have some other way to - detect memcache server failures. -""" - __author__ = "Charles Gordon" import errno @@ -175,7 +120,7 @@ class Client(object): """ A client for a single memcached server. - Keys and Values: + Keys and Values ---------------- Keys must have a __str__() method which should return a str with no more @@ -194,7 +139,7 @@ class Client(object): already implemented serializers, including one that is compatible with the python-memcache library. - Serialization and Deserialization: + Serialization and Deserialization ---------------------------------- The constructor takes two optional functions, one for "serialization" of @@ -206,19 +151,23 @@ class Client(object): Here is an example using JSON for non-str values: - def serialize_json(key, value): - if type(value) == str: - return value, 1 - return json.dumps(value), 2 + .. code-block:: python + + def serialize_json(key, value): + if type(value) == str: + return value, 1 + return json.dumps(value), 2 + + def deserialize_json(key, value, flags): + if flags == 1: + return value + + if flags == 2: + return json.loads(value) - def deserialize_json(key, value, flags): - if flags == 1: - return value - if flags == 2: - return json.loads(value) - raise Exception("Unknown flags for value: {1}".format(flags)) + raise Exception("Unknown flags for value: {1}".format(flags)) - Error Handling: + Error Handling --------------- All of the methods in this class that talk to memcached can throw one of |