def deploy_redis_instance(redis_env_folder, port):
    """
    Deploys a new redis instance in the specified folder. A redis instance will be able to serve
    16 different databases. An instance is linked to a port. The folder should exist.

    Remarks: A redis conf file will be created in the folder, whose name will depend on the port chosen.
    A redis instance for the same port cannot be deployed on the same folder.

    This task will not check whether the redis instance is deployed properly. That will be done
    in a different task.

    As of now it is not possible to customize the Redis config files. If that feature is ever needed
    it could be easily added in the future.


    @param redis_env_folder: Folder on which to create the redis conf files that will define the instance,
    and that eventually will be used to start the same instance easily. If it doesn't exist it will be created.
    If it is not a folder then an exception will be thrown.
    @param port: Port under which the new Redis instance will listen.

    @return: True if the instance is supposedly deployed successfully. An exception is otherwise thrown.
    """

    # Ensure that the specified folder exists already.
    if not os.path.exists(redis_env_folder):
        os.mkdir(redis_env_folder)
        if not os.path.isdir(redis_env_folder):
            raise Exception("Could not create the redis env folder %s. We cannot deploy the Redis instance." % redis_env_folder)

    if not os.path.isdir(redis_env_folder):
        raise Exception(
            "The specified redis folder (%s) is not a directory. We cannot deploy the Redis instance." % redis_env_folder)

    # Generate the config file.
    conf = StringIO.StringIO()
    conf.write("port %d \n" % port)
    conf.write("daemonize yes \n")
    conf.write("logfile %s \n" % (os.path.join(redis_env_folder, "redis_%d_logfile.txt" % port)))
    if DEBUG:
        conf.write("loglevel verbose \n")

    config_file_name = "redis_%d.conf" % port

    # Make sure the config file doesn't exist already.
    if os.path.exists(os.path.join(redis_env_folder, config_file_name)):
        raise AlreadyDeployedException()

    # Write it to disk.
    f = file(os.path.join(redis_env_folder, config_file_name), "w")
    f.write(conf.getvalue())
    f.close()

    return True
dataset/ETHPy150Open weblabdeusto/weblabdeusto/tools/wcloud/wcloud/actions/redis_actions.py/deploy_redis_instance/original