kazoo.recipe.counter¶
Zookeeper Counter
Maintainer: | None |
---|---|
Status: | Unknown |
New in version 0.7: The Counter class.
Public API¶
- class kazoo.recipe.counter.Counter(client, path, default=0)[source]¶
Kazoo Counter
A shared counter of either int or float values. Changes to the counter are done atomically. The general retry policy is used to retry operations if concurrent changes are detected.
The data is marshaled using repr(value) and converted back using type(counter.default)(value) both using an ascii encoding. As such other data types might be used for the counter value.
Counter changes can raise BadVersionError if the retry policy wasn’t able to apply a change.
Example usage:
zk = KazooClient() counter = zk.Counter("/int") counter += 2 counter -= 1 counter.value == 1 counter = zk.Counter("/float", default=1.0) counter += 2.0 counter.value == 3.0
- __init__(client, path, default=0)[source]¶
Create a Kazoo Counter
Parameters:
- client – A KazooClient instance.
- path – The counter path to use.
- default – The default value.