| 1 |
======== |
| 2 |
Usage |
| 3 |
======== |
| 4 |
|
| 5 |
You can find examples in ``etcd3gw/examples`` and look at ``etcd3gw/client.py``. |
| 6 |
|
| 7 |
Basic usage example:: |
| 8 |
|
| 9 |
from etcd3gw.client import Etcd3Client |
| 10 |
|
| 11 |
client = Etcd3Client(host='localhost', port=2379) |
| 12 |
|
| 13 |
# Put key |
| 14 |
client.put(key='foo', value='bar') |
| 15 |
|
| 16 |
# Get key |
| 17 |
client.get(key='foo') |
| 18 |
|
| 19 |
# Get all keys |
| 20 |
client.get_all() |
| 21 |
|
| 22 |
|
| 23 |
# Create lease and use it |
| 24 |
lease = client.lease(ttl=100) |
| 25 |
|
| 26 |
client.put(key='foo', value='bar', lease=lease) |
| 27 |
|
| 28 |
# Get lease keys |
| 29 |
lease.keys() |
| 30 |
|
| 31 |
# Refresh lease |
| 32 |
lease.refresh() |
| 33 |
|
| 34 |
|
| 35 |
# Use watch |
| 36 |
watcher, watch_cancel = client.watch(key='KEY') |
| 37 |
|
| 38 |
for event in watcher: # blocks until event comes, cancel via watch_cancel() |
| 39 |
print(event) |
| 40 |
# modify event: {'kv': {'mod_revision': '8', 'version': '3', 'value': 'NEW_VAL', 'create_revision': '2', 'key': 'KEY', 'lease': '7587847878767953426'}} |