zoukankan      html  css  js  c++  java
  • python使用etcd

    import sys
    import etcd
    
    client = etcd.Client(
        host='127.0.0.1',
        port=2379,
        allow_reconnect=True)
    client.delete('/nodes/', recursive=True, dir=True)
    client.write('/nodes/n1', 1)
    print 'node n1 value is %s' % client.read('/nodes/n1').value
    try:
        client.write('/nodes/n1', 3, prevExist=False)
    except Exception as e:
        print e.message
    print 'node n1 value is %s after prevExist=False' % client.read('/nodes/n1').value
    try:
        client.write('/nodes/n1', 3, prevValue=2)
    except Exception as e:
        print e.message
    print 'node n1 value is %s after prevValue=2' % client.read('/nodes/n1').value
    client.write('/nodes/n1', 3, prevValue=1)
    print 'node n1 value is %s after prevValue=1' % client.read('/nodes/n1').value
    client.write('/nodes/n2', 2)
    r3 = client.read('/nodes/n2')
    print 'node n2 value is %s' % r3.value
    r3.value += 5
    client.update(r3)
    r4 = client.read('/nodes/n2')
    print 'node n2 value is %s after update' % r4.value
    watcher = client.eternal_watch('/nodes/n1')
    for rsp in watcher:
        print '/nodes/n1 value change to %s' % watcher.value
        sys.stdout.flush()
    ——————————————————————————————————————————
    修改节点值:
    后台打印:
  • 相关阅读:
    剑指offer 把字符串转换成整数 python
    剑指offer 重建二叉树 python
    LeetCode 82 删除排序链表中的重复元素 II python
    LeetCode 142 环形链表 II python
    hashlib
    configparser
    正则
    logging
    模块
    文件操作
  • 原文地址:https://www.cnblogs.com/small-office/p/9394810.html
Copyright © 2011-2022 走看看