Python 官方文档:入门教程 => 点击学习
ZooKeeper给python提供了几种api 具体代码请参考我的GitHub。 1.引用kazoo lib API DOC: Http://kazoo.readthedocs.io/en/latest/install.html Cod
具体代码请参考我的GitHub。
1.引用kazoo lib
API DOC:
Http://kazoo.readthedocs.io/en/latest/install.html
Code:
# -*- 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:
# -*- 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("","")
--结束END--
本文标题: Zookeeper学习笔记 --- Py
本文链接: https://www.lsjlt.com/news/188349.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0