redis_tree.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # coding: utf-8
  2. import redis
  3. import sys
  4. redis_master_list = ['192.168.4.11:6379',]
  5. def getredisinfo(ip, port):
  6. try:
  7. r = redis.StrictRedis(host=ip, port=port, db=0)
  8. # print 'redis ip:', ip
  9. # print 'role:', r.info()['role']
  10. # print 'used_memory_human:', r.info()['used_memory_human']
  11. # print 'connected_clients:', r.info()['connected_clients']
  12. # print 'blocked_clients:', r.info()['blocked_clients']
  13. # print 'connected_slaves:', r.info()['connected_slaves']
  14. # print '--' * 60
  15. # for k,v in r.info().items():
  16. # print k,v
  17. # sys.exit()
  18. if r.info().get('slave0'):
  19. n = 0
  20. while 1:
  21. slave_num = 'slave' + str(n)
  22. if not r.info().get(slave_num):
  23. break
  24. print slave_num, r.info()[slave_num]
  25. ip = r.info()[slave_num]['ip']
  26. port = r.info()[slave_num]['port']
  27. getredisinfo(ip, port)
  28. n += 1
  29. except redis.exceptions.ConnectionError:
  30. print 'Unable to connect %s:%s' % (ip, port)
  31. for host in redis_master_list:
  32. print '==' * 60
  33. ip,port = host.split(':')
  34. getredisinfo(ip, int(port))