import logging
import json


def add_value_to_list_key(redis_con, key, value, value_format=None, value_encode=None):
    """
        Purpose:
            add value to key holding list
        Args:
            redis_con (Redis StrictRedis): Connection
                to Redis database
            key (Object): key to set in Redis
            value (Object): value to set in Redis for the specified key
        Return
            was_successful (bool): whether or not the
                command was successful running
    """
    logging.info("Appending Value to Key {0}: {1}".format(key, value))

    if value_format == "json":
        value = json.dumps(value)
    if value_encode:
        value = value.encode("utf-8")

    try:
        redis_con.lpush(key, value)
    except Exception as err:
        logging.error("Error Setting Key {0}: {1}".format(key, value))
        return False

    return True