1. 程式人生 > >py訪問Redis和zk操作

py訪問Redis和zk操作

and cookie byte pre pos test cli dmi per

# -----------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)
xx = rc.info(‘th:jsevent*‘)
x = rc.hgetall(‘t00‘)
y = rc.hgetall(‘th‘)
z = rc.hgetall(‘th0‘)


# -------------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()


py訪問Redis和zk操作