uncloud/uncloud/common/counters.py
2020-01-10 00:03:10 +05:00

21 lines
405 B
Python

from uncloud.common.shared import shared
def increment_etcd_counter(key):
kv = shared.etcd_client.get(key)
if kv:
counter = int(kv.value)
counter = counter + 1
else:
counter = 1
shared.etcd_client.put(key, str(counter))
return counter
def get_etcd_counter(key):
kv = shared.etcd_client.get(key)
if kv:
return int(kv.value)
return None