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


Python Bucket.upsert_multi方法代码示例

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


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

示例1: SDKClient

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

#.........这里部分代码省略.........
            try:
                time.sleep(10)
                return self.cb.remove(key, cas=cas, quiet=quiet, persist_to=persist_to, replicate_to=replicate_to)
            except CouchbaseError as e:
                raise

    def delete(self, keys, quiet=True, persist_to=0, replicate_to=0):
        return self.remove(self, keys, quiet=quiet, persist_to=persist_to, replicate_to=replicate_to)

    def remove_multi(self, keys, quiet=True, persist_to=0, replicate_to=0):
        try:
            self.cb.remove_multi(keys, quiet=quiet, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.remove_multi(keys, quiet=quiet, persist_to=persist_to, replicate_to=replicate_to)
            except CouchbaseError as e:
                raise

    def set(self, key, value, cas=0, ttl=0, format=None, persist_to=0, replicate_to=0):
        return self.upsert(key, value, cas=cas, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)

    def upsert(self, key, value, cas=0, ttl=0, format=None, persist_to=0, replicate_to=0):
        try:
            self.cb.upsert(key, value, cas, ttl, format, persist_to, replicate_to)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.upsert(key, value, cas, ttl, format, persist_to, replicate_to)
            except CouchbaseError as e:
                raise

    def set_multi(self, keys, ttl=0, format=None, persist_to=0, replicate_to=0):
        return self.upsert_multi(keys, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)

    def upsert_multi(self, keys, ttl=0, format=None, persist_to=0, replicate_to=0):
        try:
            self.cb.upsert_multi(keys, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.upsert_multi(keys, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
            except CouchbaseError as e:
                raise

    def insert(self, key, value, ttl=0, format=None, persist_to=0, replicate_to=0):
        try:
            self.cb.insert(key, value, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.insert(key, value, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
            except CouchbaseError as e:
                raise

    def insert_multi(self, keys,  ttl=0, format=None, persist_to=0, replicate_to=0):
        try:
            self.cb.insert_multi(keys, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
        except CouchbaseError as e:
            try:
                time.sleep(10)
                self.cb.insert_multi(keys, ttl=ttl, format=format, persist_to=persist_to, replicate_to=replicate_to)
            except CouchbaseError as e:
                raise

    def touch(self, key, ttl = 0):
开发者ID:EricACooper,项目名称:testrunner,代码行数:70,代码来源:sdk_client.py

示例2: N1QLQuery

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import upsert_multi [as 别名]
    'utilikilt1_speaker': {
        'type': 'product',
        'name': 'Utilikilt with Bluetooth Speaker in Rear',
        'price': 124.95,
        'categories': ['clothing', 'electronics', 'technology']
    }
}

# Delete any prior products so we start with a clean dataset
meta = cb.n1ql_query(
    N1QLQuery('DELETE from default WHERE type=$1', 'product')
).execute().meta
print 'Deleted {0} items!'.format(meta['metrics'].get('mutationCount', 0))

# Everything's 25% off!
cb.upsert_multi(docs)
query = N1QLQuery(
    'UPDATE default '
    'SET sale_price=ROUND(price-(price * 0.25), 2) '
    'WHERE type=$1'
    'RETURNING name, price, sale_price',
    'product'
)
for row in cb.n1ql_query(query):
    print '{0} WAS: {1:2}. NOW ONLY {2:2}'.format(
        row['name'], row['price'], row['sale_price'])

# Show how we can update a single document by its ID
query = N1QLQuery(
    'UPDATE default USE KEYS $keys SET description=$desc',
    keys=['utilikilt1_speaker'],
开发者ID:Jason-Bai,项目名称:devguide-examples,代码行数:33,代码来源:n1ql-update-delete.py

示例3: Bucket

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

bucket = Bucket("couchbase://localhost/retail")
f = open('retail.txt','r')
count = 1
inserts = dict()

for line in f:
    items = map(int, line.strip().split(" "))
    inserts["order::%d" % count] = {'type': 'order', 'items': items}
    count += 1
    if count % 1000 == 0:
        bucket.upsert_multi(inserts)
        inserts = dict()
        print "Inserted %d docs" % count
bucket.upsert_multi(inserts)
print
print "Finished inserting %d total documents." % count
开发者ID:Avalon-Consulting-LLC,项目名称:couchbase-n1ql-mba,代码行数:20,代码来源:tocb.py

示例4: Bucket

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

示例5: range

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import upsert_multi [as 别名]
if options.create_design:
    bm = c.bucket_manager()
    bm.design_create('search_keywords', DESIGN, use_devmode=False, syncwait=5)

NOUNS = ['cow', 'cat', 'dog', 'computer', 'WMD']
ADJECTIVES = ['happy', 'sad', 'thoughtful', 'extroverted']

kv = {}

for x in range(options.number_of_terms):
    n = random.choice(NOUNS)
    a = random.choice(ADJECTIVES)
    kv[" ".join([a, n])] = random.randint(1, 100000)

c.upsert_multi(kv)

vret = c.query('search_keywords',
               'top_keywords',
               limit=10,
               descending=True)

for row in vret:
    pprint.pprint(row, indent=4)

# Sample output:
#[   {   u'id': u'WMD sad', u'key': 92772, u'value': None},
#    {   u'id': u'WMD thoughtful', u'key': 76222, u'value': None},
#    {   u'id': u'cow happy', u'key': 71984, u'value': None},
#    {   u'id': u'computer sad', u'key': 68849, u'value': None},
#    {   u'id': u'cat thoughtful', u'key': 68417, u'value': None},
开发者ID:Fabma,项目名称:couchbase-python-client,代码行数:32,代码来源:search_keywords.py

示例6: email

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import upsert_multi [as 别名]
        return self.value['email']
    @email.setter
    def email(self, value):
        self.value['email'] = value

cb = Bucket('couchbase://localhost/default')
single_player = Player.create("bob", "[email protected]", cb)
single_player.score += 100
single_player.save(cb)

# Let's try multiple players
players = ItemSequence([Player(x, create_structure=True)
           for x in ("joe", "jim", "bill", "larry")])

# Save them all
cb.upsert_multi(players)

# Give them all some points
for p, options in players:
    p.score += randint(20, 2000)
    # also set the email?
    if not p.email:
        p.email = "{0}@{0}.notspecified.com".format(p.name)

cb.replace_multi(players)
all_players = ItemSequence([x[0] for x in players] + [single_player])

INDENT = " " * 3
for player in all_players.sequence:
    print "Name:", player.name
    print INDENT , player
开发者ID:couchbase,项目名称:couchbase-python-client,代码行数:33,代码来源:item.py

示例7: createLoginInfo

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import upsert_multi [as 别名]
		#Add this object to the main dictionary to be included in the batch upsert
		pending_kv[id] = j

		#Iterate uid for the for loop
		uid += 1

		#Create the remaining documents for the profile.
		createLoginInfo(id)
		createSecRoles(id)
		createSecQuestions(id)

		#Batch up the objects to be written.
		if len(pending_kv) > 50:
			bucket.upsert_multi(pending_kv)
			pending_kv.clear()

uidcap = args.numtocreate + 1

pending_kv = {}

#Call main function. This was originally set into its own function
createUserProfile(uidcap)

#Clear out any remaining objects.
bucket.upsert_multi(pending_kv)

print("Generated " + str(args.numtocreate) + " profile(s) and took "+str(datetime.datetime.now() - start))+ " to do it."

sys.exit()
开发者ID:synchrophoto,项目名称:Couchbase-schema-building-tools,代码行数:31,代码来源:user-profile-gen.py

示例8: CouchbaseMemcacheMirror

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


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