Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for riak key value database. Yet another Dynamo based.

  • Loading branch information...
commit 438fadf5ea74e7a80b813218e30af3c868a41cf3 1 parent 9d7c029
Didip Kerabat authored
Showing with 48 additions and 2 deletions.
  1. +45 −0 beaker_extensions/riak.py
  2. +3 −2 setup.py
View
45 beaker_extensions/riak.py
@@ -0,0 +1,45 @@
+import logging
+from beaker.exceptions import InvalidCacheBackendError
+
+from beaker_extensions.nosql import Container
+from beaker_extensions.nosql import NoSqlManager
+
+try:
+ import riak
+except ImportError:
+ raise InvalidCacheBackendError("Riak cache backend requires the 'riak' library")
+
+log = logging.getLogger(__name__)
+
+class RiakManager(NoSqlManager):
+ '''
+ Riak Python client packages data in JSON by default.
+ '''
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+
+ def open_connection(self, host, port):
+ self.db_conn = riak.RiakClient(host=host, port=int(port))
+ self.bucket = self.db_conn.bucket('beaker_cache')
+
+ def __contains__(self, key):
+ return self.bucket.get(key).exists()
+
+ def set_value(self, key, value):
+ self.bucket.new(key, value).store()
+
+ def __getitem__(self, key):
+ return self.bucket.get(key)
+
+ def __delitem__(self, key):
+ self.bucket.get(key).delete()
+
+ def do_remove(self):
+ raise Exception("Unimplemented")
+
+ def keys(self):
+ raise Exception("Unimplemented")
+
+
+class RiakContainer(Container):
+ namespace_manager = RiakManager
View
5 setup.py
@@ -23,9 +23,10 @@
entry_points="""
# -*- Entry points: -*-
[beaker.backends]
- dynomite = beaker_extensions.dynomite_:DynomiteManager
redis = beaker_extensions.redis_:RedisManager
- ringo = beaker_extensions.ringo:RingoManager
tyrant = beaker_extensions.tyrant_:TokyoTyrantManager
+ riak = beaker_extensions.riak:RiakManager
+ dynomite = beaker_extensions.dynomite_:DynomiteManager
+ ringo = beaker_extensions.ringo:RingoManager
""",
)
Please sign in to comment.
Something went wrong with that request. Please try again.