import time
import json
#from redis.sentinel import Sentinel
import connect
import sys
if __name__ == '__main__':
    # ======Try to connect NEON server
  
    #sentinel=Sentinel([('10.1.53.240', 9001),('10.1.53.240', 9011),('10.1.53.240', 9021)], socket_timeout=0.1)
    #sentinel=Sentinel([('10.1.33.141', 9001),('10.1.33.141', 9011),('10.1.33.141', 9021)], socket_timeout=0.1)
    #r=sentinel.master_for('neonmaster', socket_timeout=20, password='sanlie;123')
    ip_port =  [('10.1.33.141', 9001), ('10.1.33.145',9001)]
    passwd = 'sanlie;123'
    r= connect.connectNeon(ip_port, passwd, 10)
    r_read = r.getRedisRead()

    '''
    moduleList=['module131', 'module132', 'module133', 'module231', 'module232', 'module233', 'module322', 'module331', 'module332', 'module333', 'module341', 'module342', 'module343', 'module422', 'module431', 'module432', 'module433', 'module441', 'module442', 'module443', 'module521', 'module522', 'module523', 'module531', 'module532', 'module533', 'module541', 'module542', 'module543', 'module621', 'module622', 'module623', 'module631', 'module632', 'module633', 'module641', 'module642', 'module643']

    for name in moduleList:
        path="/GPPD/workspace/MantidData/"+name+"/neutroncounts"
        tmp=r_read.get(path)
        #data=json.loads(tmp)
        print name, " neutron counts:",tmp
    path2="/GPPD/workspace/MantidData/neutroncounts"
    print "total neutron counts: ",r_read.get(path2)
    '''
    n1=r_read.get("/GPPD/workspace/MantidData/monitor2/neutroncounts")
    n2=r_read.get("/GPPD/workspace/MantidData/neutroncounts")
    print "monitor: ", n1, " detector: ",n2
