码迷,mamicode.com
首页 > 编程语言 > 详细

python-etcd3

时间:2020-01-08 21:11:17      阅读:380      评论:0      收藏:0      [点我收藏+]

标签:spl   obj   ref   count   efi   test   etc   type   python   

import etcd3

etcd = etcd3.client(host="192.168.5.41", port=2379,
                    ca_cert="E://ssl/kube-ca.pem",
                    cert_cert="E://ssl/kube-etcd-192-168-5-41.pem",
                    cert_key="E://ssl/kube-etcd-192-168-5-41-key.pem")
                    
print(etcd)  ## <etcd3.client.Etcd3Client object at 0x0000000002EC4240>

result = etcd.get("/testkey")
print(type(result))  ## <class 'tuple'>
print(result[0])   ##  b'111111 '

watch_count = 0
events_iterator, cancel = etcd.watch_prefix("/testkey/")
for event in events_iterator:
    print(event) 
    ## <class 'etcd3.events.PutEvent'> key=b'/testkey/5' value=b'1234'
    
    event_str = str(event)
    
    print(isinstance(event, etcd3.events.PutEvent)) ## True
    
    print("key = %s " % event_str.split(' ')[2].split('=')[1])  
    ## key = b'/testkey/5'
    
    watch_count += 1
    if watch_count > 10:
        cancel()
        
        

python-etcd3

标签:spl   obj   ref   count   efi   test   etc   type   python   

原文地址:https://www.cnblogs.com/zhangjxblog/p/12168341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!