-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathkv.ts
32 lines (27 loc) · 880 Bytes
/
kv.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { FrameNotificationDetails } from "@farcaster/frame-sdk";
import { Redis } from "@upstash/redis";
const redis = new Redis({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
});
function getUserNotificationDetailsKey(fid: number): string {
return `frames-v2-demo:user:${fid}`;
}
export async function getUserNotificationDetails(
fid: number
): Promise<FrameNotificationDetails | null> {
return await redis.get<FrameNotificationDetails>(
getUserNotificationDetailsKey(fid)
);
}
export async function setUserNotificationDetails(
fid: number,
notificationDetails: FrameNotificationDetails
): Promise<void> {
await redis.set(getUserNotificationDetailsKey(fid), notificationDetails);
}
export async function deleteUserNotificationDetails(
fid: number
): Promise<void> {
await redis.del(getUserNotificationDetailsKey(fid));
}