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


Python Bucket.set方法代码示例

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


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

示例1: __init__

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

    def __init__(self):
        from couchbase.n1ql import N1QLQuery
        from multiprocessing import Manager, Lock
        self.cb = Bucket('couchbase://172.23.123.38/bucket-1')
        self.row_iter = self.cb.n1ql_query(N1QLQuery('select meta().id from `bucket-1`'))
        self.lock = Lock()
        self.dsize = 1000000
        self.dateiter = Manager().dict({key: None for key in ['2013-10-17', '2013-11-17', '2014-02-09', '2015-11-26']})
        self.dateiter['2013-10-17'] = .65 * self.dsize
        self.dateiter['2013-11-17'] = .2 * self.dsize
        self.dateiter['2014-02-09'] = .1 * self.dsize
        self.dateiter['2015-11-26'] = .05 * self.dsize
        self.cycledates = itertools.cycle(self.dateiter.keys())

    def createdateset(self):
        for resultid in self.row_iter:
            '''
            Day 1 should have approximately 65% of the documents
            Day 2 should have approximately 20% of the documents
            Day 3 should have approximately 10% of the documents
            Day 4 should have approximately 5% of the documents
            format like this 2010-07-27
            '''
            val = self.cb.get(resultid["id"]).value
            self.lock.acquire()
            tmpdate = self.cycledates.next()
            val["date"] = tmpdate
            self.cb.set(resultid["id"], val)
            '''
             Critical section
            '''
            self.dateiter[tmpdate] -= 1
            if self.dateiter[tmpdate] == 0:
                self.dateiter.pop(tmpdate, None)
                self.cycledates = itertools.cycle(self.dateiter.keys())

            self.lock.release()
            print(self.dateiter)

    def run(self):
        import concurrent.futures
        with concurrent.futures.ProcessPoolExecutor(max_workers=10) as executor:
            executor.submit(self.createdateset())
开发者ID:mahesh152,项目名称:perfrunner,代码行数:47,代码来源:dataload.py

示例2: __init__

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import set [as 别名]
class Datefacet:
    def __init__(self):
        from multiprocessing import Manager, Lock
        self.cb = Bucket('couchbase://172.23.99.211/bucket-1', password="password")
        self.lock = Lock()
        self.dsize = 1000000
        self.dateiter = Manager().dict({key: None for key in ['2013-10-17', '2013-11-17', '2014-02-09', '2015-11-26']})
        self.dateiter['2013-10-17'] = .65 * self.dsize
        self.dateiter['2013-11-17'] = .2 * self.dsize
        self.dateiter['2014-02-09'] = .1 * self.dsize
        self.dateiter['2015-11-26'] = .05 * self.dsize
        self.cycledates = itertools.cycle(self.dateiter.keys())

    def createdateset(self):
        for resultid in range(0, self.dsize):
            key = hex(resultid)[2:]
            '''
            Day 1 should have approximately 65% of the documents
            Day 2 should have approximately 20% of the documents
            Day 3 should have approximately 10% of the documents
            Day 4 should have approximately 5% of the documents
            format like this 2010-07-27
            '''
            val = self.cb.get(key).value
            self.lock.acquire()
            tmpdate = next(self.cycledates)
            val["date"] = tmpdate
            self.cb.set(key, val)
            self.dateiter[tmpdate] -= 1
            if self.dateiter[tmpdate] == 0:
                self.dateiter.pop(tmpdate, None)
                self.cycledates = itertools.cycle(self.dateiter.keys())
            self.lock.release()

    def run(self):
        with concurrent.futures.ProcessPoolExecutor(max_workers=10) as executor:
            executor.submit(self.createdateset())
开发者ID:couchbase,项目名称:perfrunner,代码行数:39,代码来源:load_data.py

示例3: Bucket

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

mb = Bucket("couchbase:///memoir")

# just mention tags count in case deletion is manual
mb.set('tcount', 81)
开发者ID:shivshankardayal,项目名称:memoir,代码行数:8,代码来源:set_tcount.py

示例4: Bucket

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

mb = Bucket("couchbase:///memoir")

# just mention questions count in case deletion is manual
mb.set('qcount', 18)
开发者ID:shivshankardayal,项目名称:memoir,代码行数:8,代码来源:set_qcount.py

示例5: CBGen

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import set [as 别名]
class CBGen(CBAsyncGen):

    NODES_UPDATE_INTERVAL = 15

    TIMEOUT = 10  # seconds

    def __init__(self, **kwargs):
        self.client = Bucket(
            'couchbase://{}:{}/{}'.format(kwargs['host'],
                                          kwargs.get('port', 8091),
                                          kwargs['bucket']),
            password=kwargs['password'],
            timeout=self.TIMEOUT,
        )
        self.session = requests.Session()
        self.session.auth = (kwargs['username'], kwargs['password'])
        self.server_nodes = ['{}:{}'.format(kwargs['host'],
                                            kwargs.get('port', 8091))]
        self.nodes_url = 'http://{}:{}/pools/default/buckets/{}/nodes'.format(
            kwargs['host'],
            kwargs.get('port', 8091),
            kwargs['bucket'],
        )

    def start_updater(self):
        self.t = Thread(target=self._get_list_of_servers)
        self.t.daemon = True
        self.t.start()

    def _get_list_of_servers(self):
        while True:
            try:
                nodes = self.session.get(self.nodes_url).json()
            except Exception as e:
                logger.warn('Failed to get list of servers: {}'.format(e))
                continue
            self.server_nodes = [n['hostname'] for n in nodes['servers']]
            sleep(self.NODES_UPDATE_INTERVAL)

    @quiet
    def fts_update(self, key):
        doc = self.client.get(key).value
        if 'text' in doc and 'text2' in doc:
            tmp = doc["text2"]
            doc["text2"] = doc["text"]
            doc["text"] = tmp
        elif 'time' in doc:
            if randint(0, 1):
                doc["time"] = int(doc["time"]) >> 1
            else:
                doc["time"] = int(doc["time"]) << 1

        self.client.set(key, doc)

    @quiet
    def create(self, *args, **kwargs):
        super(CBGen, self).create(*args, **kwargs)

    @quiet
    def read(self, *args, **kwargs):
        super(CBGen, self).read(*args, **kwargs)

    @quiet
    def update(self, *args, **kwargs):
        super(CBGen, self).update(*args, **kwargs)

    @quiet
    def cas(self, *args, **kwargs):
        super(CBGen, self).cas(*args, **kwargs)

    @quiet
    def delete(self, *args, **kwargs):
        super(CBGen, self).delete(*args, **kwargs)

    def query(self, ddoc, view, query):
        node = choice(self.server_nodes).replace('8091', '8092')
        url = 'http://{}/{}/_design/{}/_view/{}?{}'.format(
            node, self.client.bucket, ddoc, view, query.encoded
        )
        t0 = time()
        resp = self.session.get(url=url)
        latency = time() - t0
        return resp.text, latency

    @quiet
    def lcb_query(self, ddoc, view, query):
        return tuple(self.client.query(ddoc, view, query=query))
开发者ID:mahesh152,项目名称:perfrunner,代码行数:89,代码来源:cbgen.py

示例6: set

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import set [as 别名]
def set(key, value, bucket = "default", password = ""):

    cb = Bucket(host=cfg.COUCHBASE_IP + "/" + self.bucket)
    cb.set({key : value})
开发者ID:DavidAlphaFox,项目名称:couchbase,代码行数:6,代码来源:sdk_client_tasks.py

示例7: Bucket

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

mb = Bucket("couchbase:///memoir")

# just mention tags count in case deletion is manual
mb.set('tcount', 18)
开发者ID:shivshankardayal,项目名称:memoir,代码行数:8,代码来源:set_ucount.py


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