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


Python Bucket.get_multi方法代码示例

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


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

示例1: check_dataloss

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get_multi [as 别名]
 def check_dataloss(self, server, bucket):
     from couchbase.bucket import Bucket
     from couchbase.exceptions import NotFoundError
     from lib.memcached.helper.data_helper import VBucketAwareMemcached
     bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name))
     rest = RestConnection(self.master)
     VBucketAware = VBucketAwareMemcached(rest, bucket.name)
     _, _, _ = VBucketAware.request_map(rest, bucket.name)
     batch_start = 0
     batch_end = 0
     batch_size = 10000
     errors = []
     while self.num_items > batch_end:
         batch_end = batch_start + batch_size
         keys = []
         for i in xrange(batch_start, batch_end, 1):
             keys.append(str(i).rjust(20, '0'))
         try:
             bkt.get_multi(keys)
             self.log.info("Able to fetch keys starting from {0} to {1}".format(keys[0], keys[len(keys)-1]))
         except Exception as e:
             self.log.error(e)
             self.log.info("Now trying keys in the batch one at a time...")
             key = ''
             try:
                 for key in keys:
                     bkt.get(key)
             except NotFoundError:
                 vBucketId = VBucketAware._get_vBucket_id(key)
                 errors.append("Missing key: {0}, VBucketId: {1}".
                               format(key, vBucketId))
         batch_start += batch_size
     return errors
开发者ID:arod1987,项目名称:testrunner,代码行数:35,代码来源:rebalancein.py

示例2: check_dataloss

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get_multi [as 别名]
 def check_dataloss(self, server, bucket, num_items):
     from couchbase.bucket import Bucket
     from couchbase.exceptions import NotFoundError,CouchbaseError
     from lib.memcached.helper.data_helper import VBucketAwareMemcached
     self.log.info("########## validating data for bucket : {} ###########".format(bucket))
     cb_version= cb_version = RestConnection(server).get_nodes_version()[:3]
     if cb_version < "5":
         bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name),timeout=5000)
     else:
         bkt = Bucket('couchbase://{0}/{1}'.format(server.ip, bucket.name),username=server.rest_username,
                      password=server.rest_password,timeout=5000)
     rest = RestConnection(self.master)
     VBucketAware = VBucketAwareMemcached(rest, bucket.name)
     _, _, _ = VBucketAware.request_map(rest, bucket.name)
     batch_start = 0
     batch_end = 0
     batch_size = 10000
     errors = []
     while num_items > batch_end:
         batch_end = batch_start + batch_size
         keys = []
         for i in xrange(batch_start, batch_end, 1):
             keys.append(str(i).rjust(20, '0'))
         try:
             bkt.get_multi(keys)
             self.log.info("Able to fetch keys starting from {0} to {1}".format(keys[0], keys[len(keys) - 1]))
         except CouchbaseError as e:
             self.log.error(e)
             ok, fail = e.split_results()
             if fail:
                 for key in fail:
                     try:
                         bkt.get(key)
                     except NotFoundError:
                         vBucketId = VBucketAware._get_vBucket_id(key)
                         errors.append("Missing key: {0}, VBucketId: {1}".
                                       format(key, vBucketId))
         batch_start += batch_size
     self.log.info("Total missing keys:{}".format(len(errors)))
     self.log.info(errors)
     return errors
开发者ID:arod1987,项目名称:testrunner,代码行数:43,代码来源:volume.py

示例3: getByView

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get_multi [as 别名]
 def getByView(self, parameter):
     bucket = Bucket(self._bucketUrl)
     options = Query()
     options.mapkey_range = (str(parameter), str(parameter))
     options.stale = False
     rows = bucket.query(self.designDocument, self._viewName, query=options)
     # the resulting row view from bucket.query is [key, value, docid, doc]
     # since we want docids, select the elements with index 2
     docids = [row[2] for row in rows]
     if len(docids) == 0:
         return []
     results = bucket.get_multi(docids).values()
     return [result.value for result in results]
开发者ID:lukedoolittle,项目名称:grokplus,代码行数:15,代码来源:repository.py

示例4: SDKClient

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

#.........这里部分代码省略.........
        try:
            self.cb.counter_multi(keys, delta=delta, initial=initial, ttl=ttl)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.counter_multi(keys, delta=delta, initial=initial, ttl=ttl)
            except CouchbaseError as e:
                raise

    def get(self, key, ttl=0, quiet=True, replica=False, no_format=False):
        try:
            rv = self.cb.get(key, ttl=ttl, quiet=quiet, replica=replica, no_format=no_format)
            return self.__translate_get(rv)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                rv = self.cb.get(key, ttl=ttl, quiet=quiet, replica=replica, no_format=no_format)
                return self.__translate_get(rv)
            except CouchbaseError as e:
                raise

    def rget(self, key, replica_index=None, quiet=True):
        try:
            data  = self.rget(key, replica_index=replica_index, quiet=None)
            return self.__translate_get(data)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                data  = self.rget(key, replica_index=replica_index, quiet=None)
                return self.__translate_get(data)
            except CouchbaseError as e:
                raise

    def get_multi(self, keys, ttl=0, quiet=True, replica=False, no_format=False):
        try:
            data = self.cb.get_multi(keys, ttl=ttl, quiet=quiet, replica=replica, no_format=no_format)
            return self.__translate_get_multi(data)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                data = self.cb.get_multi(keys, ttl=ttl, quiet=quiet, replica=replica, no_format=no_format)
                return self.__translate_get_multi(data)
            except CouchbaseError as e:
                raise

    def rget_multi(self, key, replica_index=None, quiet=True):
        try:
            data = self.cb.rget_multi(key, replica_index=None, quiet=quiet)
            return self.__translate_get_multi(data)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                data = self.cb.rget_multi(key, replica_index=None, quiet=quiet)
                return self.__translate_get_multi(data)
            except CouchbaseError as e:
                raise

    def stats(self, keys=None):
        try:
            stat_map = self.cb.stats(keys = keys)
            return stat_map
        except CouchbaseError as e:
            try:
                time.sleep(10)
                return self.cb.stats(keys = keys)
            except CouchbaseError as e:
开发者ID:EricACooper,项目名称:testrunner,代码行数:70,代码来源:sdk_client.py

示例5: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get_multi [as 别名]
#!/usr/bin/env python
from __future__ import print_function

from couchbase.bucket import Bucket

cb = Bucket('couchbase://10.0.0.31/default')

# First insert the documents we care about
cb.upsert_multi({
    'foo': {'foo': 'value'},
    'bar': {'bar': 'value'},
    'baz': {'baz': 'value'}
})

# Get them back again
rvs = cb.get_multi(['foo', 'bar', 'baz'])
for key, info in rvs.items():
    print('Value for {0}: {1}'.format(key, info.value))

# See other error handling examples showing how to handle errors
# in multi operations
开发者ID:Jason-Bai,项目名称:devguide-examples,代码行数:23,代码来源:bulk-operations.py

示例6: CouchbaseMemcacheMirror

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import get_multi [as 别名]
class CouchbaseMemcacheMirror(object):
    def __init__(self, couchbase_uri, memcached_hosts, primary=PRIMARY_COUCHBASE):
        """
        :param couchbase_uri: Connection string for Couchbase
        :param memcached_hosts: List of Memcached nodes
        :param primary: Determines which datastore is authoritative.
            This affects how get operations are performed and which datastore
            is used for CAS operations.
                PRIMARY_COUCHBASE: Couchbase is authoritative
                PRIMARY_MEMCACHED: Memcached is authoritative
            By default, Couchbase is the primary store
        :return:
        """
        self.cb = CbBucket(couchbase_uri)
        self.mc = McClient(memcached_hosts)
        self._primary = primary

    @property
    def primary(self):
        return self._primary

    def _cb_get(self, key):
        try:
            return self.cb.get(key).value
        except NotFoundError:
            return None

    def get(self, key, try_alternate=True):
        """
        Gets a document
        :param key: The key to retrieve
        :param try_alternate: Whether to try the secondary data source if the
            item is not found in the primary.
        :return: The value as a Python object
        """
        if self._primary == PRIMARY_COUCHBASE:
            order = [self._cb_get, self.mc.get]
        else:
            order = [self.mc.get, self._cb_get]

        for meth in order:
            ret = meth(key)
            if ret or not try_alternate:
                return ret

        return None

    def _cb_mget(self, keys):
        """
        Internal method to execute a Couchbase multi-get
        :param keys: The keys to retrieve
        :return: A tuple of {found_key:found_value, ...}, [missing_key1,...]
        """
        try:
            ok_rvs = self.cb.get_multi(keys)
            bad_rvs = {}
        except NotFoundError as e:
            ok_rvs, bad_rvs = e.split_results()

        ok_dict = {k: (v.value, v.cas) for k, v in ok_rvs}
        return ok_dict, bad_rvs.keys()

    def get_multi(self, keys, try_alternate=True):
        """
        Gets multiple items from the server
        :param keys: The keys to fetch as an iterable
        :param try_alternate: Whether to fetch missing items from alternate store
        :return: A dictionary of key:value. Only contains keys which exist and have values
        """
        if self._primary == PRIMARY_COUCHBASE:
            ok, err = self._cb_get(keys)
            if err and try_alternate:
                ok.update(self.mc.get_many(err))
            return ok
        else:
            ok = self.mc.get_many(keys)
            if len(ok) < len(keys) and try_alternate:
                keys_err = set(keys) - set(ok)
                ok.update(self._cb_mget(list(keys_err))[0])
            return ok

    def gets(self, key):
        """
        Get an item with its CAS. The item will always be fetched from the primary
        data store.

        :param key: the key to get
        :return: the value of the key, or None if no such value
        """
        if self._primary == PRIMARY_COUCHBASE:
            try:
                rv = self.cb.get(key)
                return key, rv.cas
            except NotFoundError:
                return None, None
        else:
            return self.mc.gets(key)

    def gets_multi(self, keys):
        if self._primary == PRIMARY_COUCHBASE:
#.........这里部分代码省略.........
开发者ID:couchbaselabs,项目名称:sk-python-couchbase-memcache-mirror,代码行数:103,代码来源:couchbase_memcache_mirror.py


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