def write_data(key, value, timeout):
    global r
    try:
        r.setex(key, value, timeout)
    except Exception as e:
        logging.exception(e)
        logging.warn('Fail to connect to the redis cache server')
def write_data(key, value, timeout):
    global r
    try:
        r.setex(key, value, timeout)
    except Exception as e:
        logging.exception(e)
        logging.warn('Fail to connect to the redis cache server')
def get_data(key):
    """
    return None or the data in the redis cache
    """
    global r
    try:
        cached = r.get(key)
        return cached.decode() if cached else None
    except Exception as e:
        logging.exception(e)
        logging.warn('Fail to connect to the redis cache server')
        return None
def get_data(key):
    """
    return None or the data in the redis cache
    """
    global r
    try:
        cached = r.get(key)
        return cached.decode() if cached else None
    except Exception as e:
        logging.exception(e)
        logging.warn('Fail to connect to the redis cache server')
        return None