前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zookeeper学习笔记 --- Py

Zookeeper学习笔记 --- Py

作者头像
py3study
发布2020-01-09 14:27:58
4600
发布2020-01-09 14:27:58
举报
文章被收录于专栏:python3python3

zookeeper给python提供了几种API

具体代码请参考我的Github。

1.引用kazoo lib

API DOC:

http://kazoo.readthedocs.io/en/latest/install.html

Code:

代码语言:javascript
复制
# -*- coding:utf-8 -*-
__author__ = 'yangxin'

from kazoo.client import KazooClient

class PyZooConn(object):
    # init function include connection method
    def __init__(self):
        self.zk = KazooClient(hosts='localhost:2182')
        self.zk.start()

    # get node data
    def get_data(self, param):
        result = self.zk.get(param)
        print result

    # create a node and input a value in this node
    def create_node(self, node, value):
        self.zk.create(node, value)


    # close the connection
    def close(self):
        self.zk.stop()

    '''
    Hypothesis there is a bunch of methods here haha :)
    '''

if __name__ == '__main__':
    pz = PyZooConn()
    pz.create_node("/test", "a value")
    pz.get_data("/test/")
    pz.close()

2.引用 zookeeper

Code:

代码语言:javascript
复制
# -*- coding:utf-8 -*-
__author__ = 'yangxin'
import zookeeper as zoo
import os


class PyZookeeper(object):
    def __init__(self):
        zk_address = os.environ.get("192.168.1.1:2181")
        self.zk = zoo.init(zk_address)

    def create_node(self, node, key,value):
        self.zk.create(node, key, value)

    def get(self, node, key):
        self.zk.get("/test", key)

    '''
    Hypothesis there is a bunch of methods here haha :)
    '''

if __name__ == '__main__':
    py_zoo = PyZookeeper()
    py_zoo.create_node("","", "")
    py_zoo.get("","")
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档