0

Configure the Eviction Policy for a Redis Cluster

by
Published Dec 20, 2024

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.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Configure the Eviction Policy for a Redis Cluster
7
 * 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.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  database_cluster_uuid: string,
12
  body: {
13
    eviction_policy:
14
      | "noeviction"
15
      | "allkeys_lru"
16
      | "allkeys_random"
17
      | "volatile_lru"
18
      | "volatile_random"
19
      | "volatile_ttl";
20
  },
21
) {
22
  const url = new URL(
23
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/eviction_policy`,
24
  );
25

26
  const response = await fetch(url, {
27
    method: "PUT",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40