__init__.py 411 B

1234567891011121314151617
  1. import time
  2. from redis import Redis, ConnectionError
  3. def connect_to_redis(host):
  4. time.sleep(2)
  5. print "Connecting to redis"
  6. while True:
  7. try:
  8. redis = Redis(host=host, db=0)
  9. redis.ping()
  10. print "Connected to redis"
  11. return redis
  12. except ConnectionError:
  13. print "Failed to connect to redis - retrying"
  14. time.sleep(1)