監控redis鍵值
阿新 • • 發佈:2019-02-08
測試過程中我們有一部分常量值放入redis,共大部分應用呼叫。但在測試過程中經常有人會清空redis,迴歸測試。so,為了穩定不去重啟應用。編寫個小指令碼,監控redis的鍵值,被人刪除了,會自動插入。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import redis,time
import datetime
pool = redis.ConnectionPool(host='192.168.210.122', port=8000)
r = redis.Redis(connection_pool=pool)
print (r.get('info'))
while True:
msClinet_key = r.get('ms_client')
if msClinet_key == None:
#print "msClinet_key is None!"
r.set('ms_client','{"zkconnect":"192.168.210.42:2181,192.168.210.43:2181,192.168.210.44:2181","retry.ms":"200","SpCode":"211172"}')
#print (r.get('ms_client'))
time.sleep(15 )
print (r.get('info'))
print (r.keys())
print (r.dbsize())