py访问Redis和zk操作

# -----------python访问redis集群-----------------------
from rediscluster import StrictRedisCluster
import requests

startup_nodes = [
{"host": "192.168.5.111", "port": 6379},
{"host": "192.168.5.112", "port": 6379},
{"host": "192.168.5.113", "port": 6379},
{"host": "192.168.5.114", "port": 6379},
{"host": "192.168.5.115", "port": 6379},
{"host": "192.168.5.116", "port": 6379}]

rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True
t = rc.keys('th:jsevent*')
for i in t:
print(i)
v = rc.hgetall(i)
print(v)



# -------------python访问zk,并设置或更新zk中字典-----------------------
from kazoo.client import KazooClient
import json
import requests

def login():
# 登录获取jwt
url1 = 'http://192.168.16.511:8100/sys/loginon'
payload1 = {'username': 'admin',
'password': '123456',
'validcode': '123548'}
r = requests.post(url1, data=payload1).cookies
# print(r['jwt'])

# 链接zk查看DebugSession
zk = KazooClient(hosts='192.168.1.1:2181') # 如果是本地那就写127.0.0.1
zk.start() # 与zookeeper连接
# node = zk.get_children('/wapn/test/')
data = {"RecvURL": "...?activityId=%d&destoken=%s",
"PacketPoolInsert": "...",
"FileUrl": "file",
"DomainUrl": "",
"ImageManaUrl": "he/",
"ResetLandUrl": "ssion",
"SSOPath": "sps",
"IsDebug": bool('true'),
"DebugSession": "",
"FileUploadPath": "/ho/files/"}
print('zk')
data['DebugSession'] = r['jwt']
zk.set('/czhhadmin/var', bytes(str(json.dumps(data, indent=2)), encoding='utf-8'))
print(json.dumps(data, indent=2))


login()


posted on 2019-03-30 13:05  WapN  阅读(394)  评论(0编辑  收藏  举报

导航