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


Python Bucket.counter方法代码示例

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


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

示例1: initialize_game_rules_bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import counter [as 别名]
def initialize_game_rules_bucket(bucket=None):
    if bucket is None:
        bucket = Bucket("couchbase://localhost/game_rules")
    # Create the game document for super mario bro's
    smb = {
        "file_name": "/home/mcsmash/dev/nestopia/smb.nes",
        "system": "NES",
        "name": "Super Mario Brothers and Duck Hunt",
    }
    try:
        bucket.insert("game:1", smb)
    except KeyExistsError:
        pass

    sprite_list = []
    for i, fn in enumerate(glob("/home/mcsmash/dev/data/game_playing/sprites/*")):
        extensionless = os.path.splitext(os.path.basename(fn))
        sprite_list.append({"id": extensionless, "path": os.path.abspath(fn)})

    try:
        bucket.insert("sprites:1", sprite_list)
    except KeyExistsError:
        pass

    try:
        bucket.remove("game_number")
    except NotFoundError:
        pass

    try:
        bucket.remove("play_number:1")
    except NotFoundError:
        pass

    bucket.counter("game_number", initial=2)
    bucket.counter("play_number:1", initial=1)
开发者ID:cbeach,项目名称:game_analysis_scratch_pad,代码行数:38,代码来源:couchbase_utils.py

示例2: SDKClient

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import counter [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

示例3: CouchbaseMemcacheMirror

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

#.........这里部分代码省略.........
                rvs = self.cb.get_multi(keys)
            except NotFoundError as e:
                rvs, _ = e.split_results()

            return {k: (v.value, v.cas) for k, v in rvs}
        else:
            # TODO: I'm not sure if this is implemented in HasClient :(
            return self.mc.gets_many(keys)

    def delete(self, key):
        st = Status()
        try:
            self.cb.remove(key)
        except NotFoundError as e:
            st.cb_error = e

        st.mc_status = self.mc.delete(key)
        return st

    def delete_multi(self, keys):
        st = Status()
        try:
            self.cb.remove_multi(keys)
        except NotFoundError as e:
            st.cb_error = e

        st.mc_status = self.mc.delete_many(keys)

    def _do_incrdecr(self, key, value, is_incr):
        cb_value = value if is_incr else -value
        mc_meth = self.mc.incr if is_incr else self.mc.decr
        st = Status()
        try:
            self.cb.counter(key, delta=cb_value)
        except NotFoundError as e:
            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()
开发者ID:couchbaselabs,项目名称:sk-python-couchbase-memcache-mirror,代码行数:70,代码来源:couchbase_memcache_mirror.py

示例4: Bucket

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

from couchbase.bucket import Bucket

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

# Remove document so we have predictable behavior in this example
# the 'quiet' argument instructs the client not to raise an exception if the
# document doesn't exist, but fail silently (the status can still be retrieved
# from the returned result object)
cb.remove('docid', quiet=True)

# Without the 'initial' parameter, this command would fail if the item doesn't exist
rv = cb.counter('docid', delta=20, initial=100)
print('Delta=20, Initial=100. Current value is:', rv.value)

rv = cb.counter('docid', delta=1)
print('Delta=1. Current value is:', rv.value)

rv = cb.counter('docid', delta=-50)
print('Delta=-50. Current value is:', rv.value)
开发者ID:Jason-Bai,项目名称:devguide-examples,代码行数:24,代码来源:counter.py

示例5: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import counter [as 别名]
                    return self.current_signal
            else:
                return {}


if __name__ == '__main__':
    rom = '/home/mcsmash/dev/nestopia/smb.nes'
    data_base_dir = '/home/mcsmash/dev/data/game_playing/frames'
    bucket = Bucket('couchbase://localhost/game_rules')
    start_screen = '/home/mcsmash/dev/data/game_playing/frames/game_1/trigger_frames/start_screen.png'
    start_screen = cv2.imread(start_screen)

    game_id = 1
    game_info = bucket.get('game:{}'.format(game_id))
    try:
        play_number = bucket.counter('play_number:{}'.format(game_id)).value
    except NotFoundError:
        play_number = bucket.counter('play_number:{}'.format(game_id), initial=1).value

    data_dir = os.path.join(data_base_dir, 'game_{}'.format(game_id))
    if not os.path.exists(data_dir):
        os.mkdir(data_dir)

    data_dir = os.path.join(data_dir, 'play_number_{}'.format(play_number))
    if not os.path.exists(data_dir):
        os.mkdir(data_dir)

    init_sequence = [
        (175, 1, {
            'start': True,
        }), (225, 1, {
开发者ID:cbeach,项目名称:game_analysis_scratch_pad,代码行数:33,代码来源:nestopia_client.py


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