Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

n1k0/NSMemcached

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README: NSMemcached 0.2.1

Author: Nicolas Perriault
Contact: np at akei com

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

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.

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).

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.

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

Nicolas Perriault, AKEI, <np at akei com>

About

A simple implementation of a namespaced Python client for memcached

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages