当前位置: 首页>>代码示例>>Python>>正文


Python Couchbase.delete方法代码示例

本文整理汇总了Python中couchbase.Couchbase.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Couchbase.delete方法的具体用法?Python Couchbase.delete怎么用?Python Couchbase.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchbase.Couchbase的用法示例。


在下文中一共展示了Couchbase.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TempDatabaseMixin

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import delete [as 别名]
class TempDatabaseMixin(object):

    temp_dbs = None
    _db = None

    def setUp(self):
        self.server = Couchbase("localhost", "Administrator", "password")

    def tearDown(self):
        if self.temp_dbs:
            for name in self.temp_dbs:
                self.server.delete(name)

    def temp_db(self):
        if self.temp_dbs is None:
            self.temp_dbs = {}
        # Find an unused database name
        while True:
            name = "couchbase-mapping-python_%d" % random.randint(0, sys.maxint)
            if name not in self.temp_dbs:
                break
        db = self.server.create(name)
        self.temp_dbs[name] = db
        return name, db

    def del_db(self, name):
        del self.temp_dbs[name]
        self.server.delete(name)

    @property
    def db(self):
        if self._db is None:
            name, self._db = self.temp_db()
        return self._db
开发者ID:hdmessaging,项目名称:couchbase-mapping-python,代码行数:36,代码来源:testutil.py

示例2: test_old_unified_client_example

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import delete [as 别名]
    def test_old_unified_client_example(self):
        from couchbase import Couchbase

        # connect to a couchbase server
        cb = Couchbase(self.host + ':' + self.port,
                       username=self.username,
                       password=self.password)
        if not cb.couch_api_base:
            raise SkipTest

        default_bucket = cb[self.bucket_name]
        default_bucket['key1'] = 'value1'

        default_bucket2 = cb.bucket(self.bucket_name)
        default_bucket2['key2'] = {'value': 'value2', 'expiration': 0}

        default_bucket.set('key3', 0, 0, 'value3')

        self.assertEqual(str(default_bucket.get('key1')[2]), 'value1')
        self.assertEqual(str(default_bucket2.get('key2')[2]), 'value2')
        self.assertEqual(str(default_bucket2['key3'][2]), 'value3')

        # create a new bucket
        try:
            newbucket = cb.create('newbucket', ram_quota_mb=100, replica=1)
        except:
            newbucket = cb['newbucket']

        # set a JSON document using the more "pythonic" interface
        newbucket['json_test'] = {'type': 'item', 'value': 'json test'}
        print 'json_test ' + str(newbucket['json_test'])
        # use the more verbose API which allows for setting expiration & flags
        newbucket.set('key4', 0, 0, {'type': 'item', 'value': 'json test'})
        print 'key4 ' + str(newbucket['key4'])

        design_doc = {"views":
                      {"all_by_types":
                       {"map":
                        '''function (doc, meta) {
                             emit([meta.type, doc.type, meta.id], doc.value);
                             // row output: ['json', 'item', 'key4'], 'json test'
                           }'''
                        },
                       },
                      }
        # save a design document
        newbucket['_design/testing'] = design_doc

        all_by_types_view = newbucket['_design/testing']['all_by_types']
        rows = all_by_types_view.results({'stale': False})
        for row in rows:
            self.assertTrue(row is not None)

        cb.delete('newbucket')
开发者ID:CanWeStudio,项目名称:couchbase-python-client,代码行数:56,代码来源:test_readme_examples.py

示例3: CouchbaseStorage

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import delete [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)"
开发者ID:CodeMonk,项目名称:will,代码行数:55,代码来源:couchbase_storage.py

示例4: test_old_unified_client_example

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import delete [as 别名]
    def test_old_unified_client_example(self):
        from couchbase import Couchbase

        # connect to a couchbase server
        cb = Couchbase(self.host + ":" + self.port, username=self.username, password=self.password)

        # create default bucket if it doesn't exist
        # try:
        #    cb.create(self.bucket_name)
        # except:
        #    pass

        default_bucket = cb[self.bucket_name]
        default_bucket["key1"] = "value1"

        default_bucket2 = cb.bucket(self.bucket_name)
        default_bucket2["key2"] = {"value": "value2", "expiration": 0, "flags": 10}

        default_bucket.set("key3", 0, 0, "value3")

        self.assertEqual(str(default_bucket.get("key1")[2]), "value1")
        self.assertEqual(str(default_bucket2.get("key2")[2]), "value2")
        self.assertEqual(str(default_bucket2["key3"][2]), "value3")

        # delete a bucket
        # cb.delete(self.bucket_name)
        # try:
        #    cb['default']
        # except Exception as ex:
        #    print ex

        # create a new bucket
        try:
            newbucket = cb.create("newbucket", ram_quota_mb=100, replica=1)
        except:
            newbucket = cb["newbucket"]

        # set a json document with a function
        # this will translate $flags and $expiration to memcached protocol
        # automatically generate the _id
        doc_id = newbucket.save({"type": "item", "value": "json test", "$flags": 25})
        print doc_id + " " + str(newbucket[doc_id])
        # use a provided _id
        doc_id = newbucket.save({"_id": "key4", "type": "item", "value": "json test", "$flags": 25})
        print doc_id + " " + str(newbucket[doc_id])

        design = {
            "_id": "_design/testing",
            "language": "javascript",
            "views": {"all": {"map": """function (doc) {\n    emit(doc, null);\n}"""}},
        }
        # save a design document
        # right now with no _rev, we can only create, we can't update
        try:
            doc_id = newbucket.save(design)
        except:
            doc_id = "_design/testing"

        if cb.couch_api_base:
            rows = newbucket.view("_design/testing/_view/all")
            for row in rows:
                self.assertTrue(row is not None)

        cb.delete("newbucket")
开发者ID:scalabl3,项目名称:couchbase-python-client,代码行数:66,代码来源:test_readme_examples.py


注:本文中的couchbase.Couchbase.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。