File: usage.rst

package info (click to toggle)
python-etcd3gw 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: python: 1,209; sh: 38; makefile: 22
file content (40 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
========
Usage
========

You can find examples in ``etcd3gw/examples`` and look at ``etcd3gw/client.py``.

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: {'kv': {'mod_revision': '8', 'version': '3', 'value': 'NEW_VAL', 'create_revision': '2', 'key': 'KEY', 'lease': '7587847878767953426'}}