Edits history of script submission #10715 for ' Configure the Eviction Policy for a Redis Cluster (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Configure the Eviction Policy for a Redis Cluster
     * To configure an eviction policy for an existing Redis cluster, send a PUT request to `/v2/databases/$DATABASE_ID/eviction_policy` specifying the desired policy.
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      body: {
        eviction_policy:
          | "noeviction"
          | "allkeys_lru"
          | "allkeys_random"
          | "volatile_lru"
          | "volatile_random"
          | "volatile_ttl";
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/eviction_policy`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago