Skip to content

couchbaselabs/sk-python-couchbase-memcache-mirror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Couchbase Memcached Mirror

This python module provides a CouchbaseMemcacheMirror class which allows mirroring of data between Couchbase and Memcached. It uses the pymemcache module for Memcached access and the couchbase module for Couchbase access.

Since the goal of this module is to introduce Couchbase to those familiar with Memcached, the module exposes a Memcached-style API (add, set, cas) rather than a Couchbase one (insert, upsert).

The class may be used in your code (using a primarily memcached-style API) to read and write data to and from Memcached and Couchbase. The class will transparently write to both Couchbase and Memcached clusters.

Run as a standalone

$ pip install -r requirements.txt
$ python couchbase_memcache_mirror -C couchbase://10.0.0.99 -M mchost1:11211 -M mchost2:11211
# Value from couchbase: {u'entry': u'Mirror value', u'updated': 1446743031.692772}
# Value from Memcached: {'entry': 'Mirror value', 'updated': 1446743031.692772}

Use in code

from couchbase_memcache_mirror import CouchbaseMemcacheMirror
mirror = CouchbaseMemcacheMirror(
    couchbase_uri='couchbase://localhost/default',
    memcached_hosts=[('localhost',11211)])

mirror.set('u:couchbase', {'user': 'Couchbase Server'}
value = mirror.get('u:couchbase')
if not value:
    print 'Couldn't retrieve value!'
value['website'] = 'http://couchbase.com'
mirror.replace('u:couchbase', value)

See the module source code for more information on implementation and API usage.

Primary and secondary data sources

This module allows you to select which data source is a primary for read and write access. This affects gets, get and cas operations: get operations are performed against the primary and cas operations are performed against the primary (the secondary being ignored)

About

Couchbase & Memcached mirroring module for Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages