Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Commit

Permalink
Add basic usage example in usage.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
gmelikov authored and dims committed Jul 30, 2020
1 parent 7f6c949 commit aa939c4
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions doc/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
Usage
========

To use etcd3-gateway in a project::
You can find examples in ``etcd3gw/examples`` and look at ``etcd3gw/client.py``.

import etcd3gw
Basic usage example::

from etcd3gw.client import Etcd3Client
client = Etcd3Client(host='localhost', port=2379)

# Put key
client.put(key='foo', value='bar')

# Get key
client.get(key='foo')

# Get all keys
client.get_all()


# Create lease and use it
lease = client.lease(ttl=100)

client.put(key='foo', value='bar', lease=lease)

# Get lease keys
lease.keys()

# Refresh lease
lease.refresh()


# Use watch
watcher, watch_cancel = client.watch(key='KEY')

for event in watcher: # blocks until event comes, cancel via watch_cancel()
print(event)
# modify event: {u'kv': {u'mod_revision': u'8', u'version': u'3', u'value': 'NEW_VAL', u'create_revision': u'2', u'key': 'KEY', u'lease': u'7587847878767953426'}}

0 comments on commit aa939c4

Please sign in to comment.