本文整理汇总了Python中couchbase._libcouchbase.Connection.incr方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.incr方法的具体用法?Python Connection.incr怎么用?Python Connection.incr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchbase._libcouchbase.Connection
的用法示例。
在下文中一共展示了Connection.incr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: incr
# 需要导入模块: from couchbase._libcouchbase import Connection [as 别名]
# 或者: from couchbase._libcouchbase.Connection import incr [as 别名]
def incr(self, key, amount=1, initial=None, ttl=0):
"""
Increment the numeric value of a key.
:param string key: A key whose counter value is to be incremented
:param int amount: an amount by which the key should be
incremented
:param initial: The initial value for the key, if it does not
exist. If the key does not exist, this value is used, and
`amount` is ignored. If this parameter is `None` then no
initial value is used
:type initial: int or `None`
:param int ttl: The lifetime for the key, after which it will
expire
:raise: :exc:`couchbase.exceptions.NotFoundError` if the key
does not exist on the bucket (and `initial` was `None`)
:raise: :exc:`couchbase.exceptions.DeltaBadvalError` if the key
exists, but the existing value is not numeric
:return:
A :class:`couchbase.libcouchbase.Result` object. The current value
of the counter may be obtained by inspecting the return value's
`value` attribute.
Simple increment::
rv = cb.incr("key")
rv.value
# 42
Increment by 10::
ok = cb.incr("key", amount=10)
Increment by 20, set initial value to 5 if it does not exist::
ok = cb.incr("key", amount=20, initial=5)
Increment three keys::
kv = cb.incr_multi(["foo", "bar", "baz"])
for key, result in kv.items():
print "Key %s has value %d now" % (key, result.value)
.. seealso::
:meth:`decr`
:meth:`incr_multi`
"""
return _Base.incr(self, key, amount, initial, ttl)