A simple implementation of a namespaced Python client for memcached
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
nsmemcached
.gitignore
LICENSE.txt
MANIFEST
README.rst
setup.py

README.rst

README: NSMemcached 0.2.1

Author: Nicolas Perriault
Contact: np at akei com

Abstract

NSMemcached is simple yet efficient Python implementation of a namespaced client for memcached on top of the python-memcached package.

Quick Start

Sample usage:

>>> from nsmemcached import Client
>>> ns_client = Client(['127.0.0.1:11211'])
>>> ns_client.set('foo', 'bar', ns='barspace')
True
>>> ns_client.set('zoo', 'baz', ns='barspace')
True
>>> ns_client.get('foo', ns='barspace')
'bar'
>>> ns_client.get('zoo', ns='barspace')
'baz'
>>> ns_client.get('foo')
>>> ns_client.get('zoo')
>>> ns_client.clear_ns('barspace')
True
>>> ns_client.get('foo', ns='barspace')
>>> ns_client.get('zoo', ns='barspace')

Yes, that simple. Other python-memcached client methods are supported as well, sharing the same signature but with a supplementary ns named argument available to optionaly declare a namespace to perform the query within:

>>> ns_client.set('foo', 1, ns='bar')
True
>>> ns_client.incr('foo', ns='bar')
2
>>> ns_client.decr('foo', ns='bar')
1
>>> ns_client.set('foo', 'bar, ns='bar')
True
>>> ns_client.append('foo', '!!!', ns='bar')
True
>>> ns_client.get('foo', ns='bar')
'bar!!!'
>>> ns_client.delete('foo', ns='bar')
True
>>> ns_client.get('foo', ns='bar')

The best way to learn about the usage of all the available methods from the API is probably to dig into the test suite code which covers 100% of them.

Caveats

Namespace keys are stored in dedicated keys, so every time you request a namespaced item you'll make two queries to the memcached server instead of one, so expect a tiny slowdown compared to the way of using the standard, non-namespaced memcached API.

Also, python-memcached client's get_multi() and set_multi() are not currently supported (yet).

Dependencies and Compatibility

NSMemcached requires the use of Python 2.4 or more recent.

Installing python-memcached package is required in order to use this library, as well as a working memcached server instance, obviously.

NSMemcached is fully compatible with the API of the standard python-memcached client.

License

This code is released under the terms of the MIT License.

Author

Nicolas Perriault, AKEI, <np at akei com>