2019-12-14 15:23:31 +00:00
|
|
|
from .etcd_wrapper import Etcd3Wrapper
|
2019-11-18 17:39:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def increment_etcd_counter(etcd_client: Etcd3Wrapper, key):
|
|
|
|
kv = etcd_client.get(key)
|
|
|
|
|
|
|
|
if kv:
|
|
|
|
counter = int(kv.value)
|
|
|
|
counter = counter + 1
|
|
|
|
else:
|
|
|
|
counter = 1
|
|
|
|
|
|
|
|
etcd_client.put(key, str(counter))
|
|
|
|
return counter
|
|
|
|
|
|
|
|
|
|
|
|
def get_etcd_counter(etcd_client: Etcd3Wrapper, key):
|
|
|
|
kv = etcd_client.get(key)
|
|
|
|
if kv:
|
|
|
|
return int(kv.value)
|
|
|
|
return None
|