本文整理汇总了Python中couchbase.Couchbase.set方法的典型用法代码示例。如果您正苦于以下问题:Python Couchbase.set方法的具体用法?Python Couchbase.set怎么用?Python Couchbase.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase.Couchbase
的用法示例。
在下文中一共展示了Couchbase.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CouchbaseStorage
# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import set [as 别名]
class CouchbaseStorage(object):
"""
A storage backend using Couchbase
You must supply a COUCHBASE_URL setting that is passed through urlparse.
All parameters supplied get passed through to Couchbase
Examples:
* couchbase:///bucket
* couchbase://hostname/bucket
* couchbase://host1,host2/bucket
* couchbase://hostname/bucket?password=123abc&timeout=5
"""
def __init__(self, settings):
url = urlparse.urlparse(settings.COUCHBASE_URL)
params = dict([
param.split('=')
for param in url.query.split('&')
])
self.couchbase = Couchbase(host=url.hostname.split(','),
bucket=url.path.strip('/'),
port=url.port or 8091,
**params)
def save(self, key, value, expire=None):
res = self.couchbase.set(key, value, ttl=expire)
return res.success
def clear(self, key):
res = self.couchbase.delete(key)
return res.success
def clear_all_keys(self):
"""
Couchbase doesn't support clearing all keys (flushing) without the
Admin username and password. It's not appropriate for Will to have
this information so we don't support clear_all_keys for CB.
"""
return "Sorry, you must flush the Couchbase bucket from the Admin UI"
def load(self, key):
try:
res = self.couchbase.get(key)
return res.value
except cb_exc.NotFoundError:
pass
def size(self):
"""
Couchbase doesn't support getting the size of the DB
"""
return "Unknown (See Couchbase Admin UI)"