-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathredisdriver.py
30 lines (26 loc) · 911 Bytes
/
redisdriver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import redis
import time
class RedisConnector():
def __init__(self,host,port,db):
self.host = host
self.port = port
self.db = db
def RedisConnect(self):
try:
Predis=redis.StrictRedis(host=self.host, port=self.port, db=self.db)
Predis.ping()
return 'Enable'
except Exception,e:
i=0
print("Try connect redis again.\n")
while(i<3):
try:
Predis=redis.StrictRedis(host=RedisHOST, port=RedisPORT, db=RedisDB)
Predis.ping()
print("Succeed to re-connect Redis.\n")
return 'Enable'
except Exception,e:
print("Error:Faile to re-connect redis:\n%s" %e)
i+=1
time.sleep(2)
return 'Unable'