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


Python Bucket.replace方法代码示例

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


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

示例1: SDKClient

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]
class SDKClient(object):
    """Python SDK Client Implementation for testrunner - master branch Implementation"""

    def __init__(self, bucket, hosts = ["localhost"] , scheme = "couchbase",
                 ssl_path = None, uhm_options = None, password=None,
                 quiet=True, certpath = None, transcoder = None):
        self.connection_string = \
            self._createString(scheme = scheme, bucket = bucket, hosts = hosts,
                               certpath = certpath, uhm_options = uhm_options)
        self.password = password
        self.quiet = quiet
        self.transcoder = transcoder
        self.default_timeout = 0
        self._createConn()

    def _createString(self, scheme ="couchbase", bucket = None, hosts = ["localhost"], certpath = None, uhm_options = ""):
        connection_string = "{0}://{1}".format(scheme, ", ".join(hosts).replace(" ",""))
        if bucket != None:
            connection_string = "{0}/{1}".format(connection_string, bucket)
        if uhm_options != None:
            connection_string = "{0}?{1}".format(connection_string, uhm_options)
        if scheme == "couchbases":
            if "?" in connection_string:
                connection_string = "{0},certpath={1}".format(connection_string, certpath)
            else:
                connection_string = "{0}?certpath={1}".format(connection_string, certpath)
        return connection_string

    def _createConn(self):
        try:
            self.cb = CouchbaseBucket(self.connection_string, password = self.password,
                                  quiet = self.quiet, transcoder = self.transcoder)
            self.default_timeout = self.cb.timeout
        except BucketNotFoundError as e:
             raise

    def reconnect(self):
        self.cb.close()
        self._createConn()

    def close(self):
        self.cb._close()

    def counter_in(self, key, path, delta, create_parents=True, cas=0, ttl=0, persist_to=0, replicate_to=0):
        try:
            return self.cb.counter_in(key, path, delta, create_parents= create_parents, cas= cas, ttl= ttl, persist_to= persist_to, replicate_to= replicate_to)
        except CouchbaseError as e:
            raise

    def arrayappend_in(self, key, path, value, create_parents=True, cas=0, ttl=0, persist_to=0, replicate_to=0):
        try:
            return self.cb.arrayappend_in(key, path, value, create_parents=create_parents, cas=cas, ttl=ttl, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            raise

    def arrayprepend_in(self, key, path, value, create_parents=True, cas=0, ttl=0, persist_to=0, replicate_to=0):
        try:
            return self.cb.arrayprepend_in(key, path, value, create_parents=create_parents, cas=cas, ttl=ttl, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            raise

    def arrayaddunique_in(self, key, path, value, create_parents=True, cas=0, ttl=0, persist_to=0, replicate_to=0):
        try:
            return self.cb.addunique_in(key, path, value, create_parents=create_parents, cas=cas, ttl=ttl, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            raise

    def arrayinsert_in(self, key, path, value, cas=0, ttl=0, persist_to=0, replicate_to=0):
        try:
            return self.cb.arrayinsert_in(key, path, value, cas=cas, ttl=ttl, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            raise

    def remove_in(self, key, path,  cas=0, ttl=0):
        try:
            self.cb.remove_in(key, path, cas = cas, ttl = ttl)
        except CouchbaseError as e:
            raise

    def mutate_in(self, key, *specs, **kwargs):
        try:
            self.cb.mutate_in(key, *specs, **kwargs)
        except CouchbaseError as e:
            raise

    def lookup_in(self, key, *specs, **kwargs):
        try:
            self.cb.lookup_in(key, *specs, **kwargs)
        except CouchbaseError as e:
            raise

    def get_in(self, key, path):
        try:
            result = self.cb.get_in(key, path)
            return self.__translate_get(result)
        except CouchbaseError as e:
            raise

    def exists_in(self, key, path):
        try:
#.........这里部分代码省略.........
开发者ID:EricACooper,项目名称:testrunner,代码行数:103,代码来源:sdk_client.py

示例2: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]
# coding: UTF-8

# setup時にbeer-sampleを登録しておく

from couchbase.bucket import Bucket
from couchbase.exceptions import CouchbaseError

c = Bucket('couchbase://localhost/beer-sample')

try:
    beer = c.get("aass_brewery-juleol")

except CouchbaseError as e:
    print "Couldn't retrieve value for key", e
    raise

doc = beer.value

print unicode("{name}, ABV: {abv}").format(name=doc['name'], abv=doc['abv'])

doc['comment'] = "Random Beer from Norway"

try:
    result = c.replace("aass_brewery-juleol", doc)
    print result

except CouchbaseError as e:
    print "Couldn't replace key"
    raise
开发者ID:tucur-prg,项目名称:vagrant,代码行数:31,代码来源:connection.py

示例3: buildDB

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]
class buildDB(object):
    def __init__(self, bucket):
        self.bucket = bucket
        self.db = Bucket(bucket, lockmode=LOCKMODE_WAIT)

    def insert_job_history(self, job):
        #
        # param: job
        # type: dict
        #
        try:
            docId = job['branch']+"-"+str(job['buildNum'])+"-"+job['platform']+"-"+job['edition']
            result = self.db.insert(docId, job)
            logger.debug("{0}".format(result))
        except CouchbaseError as e:
            if e.rc == 12: 
                logger.warning("Couldn't create job history {0} due to error: {1}".format(docId, e))

        return docId

    def update_job_history(self, job):
        #
        # param: job
        # type: dict
        #
        try:
            docId = job['branch']+"-"+str(job['buildNum'])+"-"+job['platform']+"-"+job['edition']
            result = self.db.replace(docId, job)
            logger.debug("{0}".format(result))
        except CouchbaseError as e:
            if e.rc == 13: 
                logger.error("Couldn't update job history. {0} does not exist {1}".format(docId, e))
             
    def insert_build_history(self, bldHistory):
        #
        # param: bldHistory
        # type: dict
        #
        # Job history should be inserted prior to this
        #
        try:
            docId = bldHistory['branch']+"-"+str(bldHistory['buildNum'])
            result = self.db.insert(docId, bldHistory)
            logger.debug("{0}".format(result))
        except CouchbaseError as e:
            if e.rc == 12: 
                logger.warning("Couldn't create build history {0} due to error: {1}".format(docId, e))

        return docId

    def update_build_history(self, bldHistory):
        try:
            docId = bldHistory['branch']+"-"+str(bldHistory['buildNum'])
            result = self.db.replace(docId, bldHistory)
            logger.debug("{0}".format(result))
        except CouchbaseError as e:
            if e.rc == 13: 
                logger.error("Couldn't update build history {0} does not exist {1}".format(docId, e))

    def insert_commit(self, commit):
        try:
            docId = commit['repo']+"-"+str(commit['commitId'])
            result = self.db.insert(docId, commit)
            logger.debug("{0}".format(result))
        except CouchbaseError as e:
            if e.rc == 12: 
                logger.error("Couldn't create commit history {0} due to error: {1}".format(docId, e))

        return docId

    def query_commit(self, commitId):
        readResult = self.db.get(commitId)
        return readResult.value

    def find_prev_build(self, dashboard_name, criteria="undefined"):
        logger.debug("Not implemented")
        bldNum = 0
        return bldNum

    def retrieve_incomplete_builds(self, dashboard_name):
        # Get previously incomplete builds
        logger.debug("{0}...not implemented".format(dashboard_name))

    def query_buildHistory(self, bldHistory):
        docId = bldHistory['branch']+"-"+str(bldHistory['buildNum'])
        readResult = self.db.get(docId)
        return readResult.value

    def __repr__(self):
        return ("buildDB(history, num_jobs)".format(self))
开发者ID:Chippiewill,项目名称:build,代码行数:92,代码来源:buildDB.py

示例4: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]
cb = Bucket('couchbase://10.0.0.31/default')

# This always works!
print('Upserting')
cb.upsert('docid', {'property': 'value'})
print('Getting item back. Value is:',
      cb.get('docid').value)
print('...')

print('Will try to insert the document. Should fail because the item already exists..')
try:
    cb.insert('docid', {'property': 'value'})
except E.KeyExistsError:
    print('Insert failed because item already exists!')
print('...')

print('Replacing the document. This should work because the item already exists')
cb.replace('docid', {'property': 'new_value'})
print('Getting document again. Should contain the new contents:',
      cb.get('docid').value)
print('...')

print('Removing document.')
# Remove the item, then try to replace it!
cb.remove('docid')
print('Replacing document again. Should fail because document no longer exists')
try:
    cb.replace('docid', {'property': 'another value'})
except E.NotFoundError:
    print('Get failed since item does not exist')
开发者ID:Jason-Bai,项目名称:devguide-examples,代码行数:32,代码来源:updating.py

示例5: CouchbaseMemcacheMirror

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]

#.........这里部分代码省略.........
            st.cb_error = e

        st.mc_status = mc_meth(key, value)

    def incr(self, key, value):
        return self._do_incrdecr(key, value, True)

    def decr(self, key, value):
        return self._do_incrdecr(key, value, False)

    def touch(self, key, expire=0):
        st = Status()
        try:
            self.cb.touch(key, ttl=expire)
        except NotFoundError as e:
            st.cb_error = st

        st.mc_status = self.mc.touch(key)

    def set(self, key, value, expire=0):
        """
        Write first to Couchbase, and then to Memcached
        :param key: Key to use
        :param value: Value to use
        :param expire: If set, the item will expire in the given amount of time
        :return: Status object if successful (will always be success).
                 on failure an exception is raised
        """
        self.cb.upsert(key, value, ttl=expire)
        self.mc.set(key, value, expire=expire)
        return Status()

    def set_multi(self, values, expire=0):
        """
        Set multiple items.
        :param values: A dictionary of key, value indicating values to store
        :param expire: If present, expiration time for all the items
        :return:
        """
        self.cb.upsert_multi(values, ttl=expire)
        self.mc.set_many(values, expire=expire)
        return Status()

    def replace(self, key, value, expire=0):
        """
        Replace existing items
        :param key: key to replace
        :param value: new value
        :param expire: expiration for item
        :return: Status object. Will be OK
        """
        status = Status()
        try:
            self.cb.replace(key, value, ttl=expire)
        except NotFoundError as e:
            status.cb_error = e

        status.mc_status = self.mc.replace(key, value, expire=expire)
        return status

    def add(self, key, value, expire=0):
        status = Status()
        try:
            self.cb.insert(key, value, ttl=expire)
        except KeyExistsError as e:
            status.cb_error = e

        status.mc_status = self.mc.add(key, value, expire=expire)
        return status

    def _append_prepend(self, key, value, is_append):
        cb_meth = self.cb.append if is_append else self.cb.prepend
        mc_meth = self.mc.append if is_append else self.mc.prepend
        st = Status()

        try:
            cb_meth(key, value, format=FMT_UTF8)
        except (NotStoredError, NotFoundError) as e:
            st.cb_error = e

        st.mc_status = mc_meth(key, value)

    def append(self, key, value):
        return self._append_prepend(key, value, True)

    def prepend(self, key, value):
        return self._append_prepend(key, value, False)

    def cas(self, key, value, cas, expire=0):
        if self._primary == PRIMARY_COUCHBASE:
            try:
                self.cb.replace(key, value, cas=cas, ttl=expire)
                self.mc.set(key, value, ttl=expire)
                return True
            except KeyExistsError:
                return False
            except NotFoundError:
                return None
        else:
            return self.mc.cas(key, value, cas)
开发者ID:couchbaselabs,项目名称:sk-python-couchbase-memcache-mirror,代码行数:104,代码来源:couchbase_memcache_mirror.py

示例6: SessionStore

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import replace [as 别名]
class SessionStore(SessionBase):
    """
    A couchbase-based session store.
    """

    def __init__(self, session_key=None):
        super(SessionStore, self).__init__(session_key)
        host = settings.COUCHBASE_HOST
        bucket = settings.COUCHBASE_BUCKET
        self.server = Bucket('couchbase://' + host + '/' + bucket)

    @property
    def cache_key(self):
        return self._get_or_create_session_key()

    def load(self):
        try:
            session_data = self.server.get(
                self._get_or_create_session_key()
            )
            return session_data.value
        except:
            self._session_key = None
            return {}

    def create(self):
        while True:
            self._session_key = self._get_new_session_key()
            try:
                self.save(must_create=True)
            except CreateError:
                continue
            self.modified = True
            return


    def save(self, must_create=False):
        if self.session_key is None:
            return self.create()
        if must_create and self.exists(self._get_or_create_session_key()):
            raise CreateError
        if must_create:
            data = self._get_session(no_load=must_create)
            self.server.insert(
                self._get_or_create_session_key(),
                data
            )
        else:
            data = self._get_session(no_load=must_create)
            self.server.replace(
                self._get_or_create_session_key(),
                data
            )


    def exists(self, session_key):
        rv = self.server.get(session_key, quiet=True)
        return rv.success


    def delete(self, session_key=None):
        if session_key is None:
            if self.session_key is None:
                return
            session_key = self.session_key
        try:
            self.server.remove(session_key)
        except:
            pass


    @classmethod
    def clear_expired(cls):
        pass
开发者ID:code137,项目名称:django-couchbase-sessions,代码行数:76,代码来源:sessions.py


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