Esempio n. 1
0
def inititalize_redis():
    global redis
    redis = None
    # Get the crdentials from the Bluemix environment
    if 'VCAP_SERVICES' in os.environ:
        app.logger.info("Using VCAP_SERVICES...")
        VCAP_SERVICES = os.environ['VCAP_SERVICES']
        services = json.loads(VCAP_SERVICES)
        creds = services['rediscloud'][0]['credentials']
        app.logger.info("Conecting to Redis on host %s port %s" %
                        (creds['hostname'], creds['port']))
        redis = connect_to_redis(creds['hostname'], creds['port'],
                                 creds['password'])
    else:
        app.logger.info(
            "VCAP_SERVICES not found, checking localhost for Redis")
        redis = connect_to_redis('127.0.0.1', 6379, None)
        if not redis:
            app.logger.info("No Redis on localhost, using: redis")
            redis = connect_to_redis('redis', 6379, None)
    if not redis:
        # if you end up here, redis instance is down.
        app.logger.error(
            '*** FATAL ERROR: Could not connect to the Redis Service')
    # Have the Pet model use Redis
    Pet.use_db(redis)
Esempio n. 2
0
 def setUp(self):
     server.inititalize_redis()
     Pet.use_db(server.redis)
     # Pet.use_db(Redis(host='127.0.0.1', port=6379))
     Pet.remove_all()