<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def clear_sessions(venv=None):
 """Clear all sessions for all sandboxes or for production."""

    if "VIRTUAL_ENV" in os.environ:
        ve = os.path.basename(os.environ["VIRTUAL_ENV"])
    else:
        ve = ""

    if venv is not None:
        ve = venv
    else:
        ve = prompt("Enter the name of the "
                    "sandbox whose sessions you would like to delete, or "
                    "\"ion\" to clear production sessions:", default=ve)

    c = "redis-cli -n {0} KEYS {1}:session:* | sed 's/\"^.*\")//g'"
    keys_command = c.format(REDIS_SESSION_DB, ve)

    keys = local(keys_command, capture=True)
    count = 0 if keys.strip() == "" else keys.count("\n") + 1

    if count == 0:
        puts("No sessions to destroy.")
        return 0

    plural = "s" if count != 1 else ""

    if not confirm("Are you sure you want to destroy {} {}" "session{}?".format(count, "production " if ve == "ion" else "", plural)):
        return 0

    if count > 0:
        local("{0}| xargs redis-cli -n " "{1} DEL".format(keys_command, REDIS_SESSION_DB))

        puts("Destroyed {} session{}.".format(count, plural))