Back to packages list

Vals using @upstash/redis

Description from the NPM package:
An HTTP/REST based Redis client built on top of Upstash REST API.
1
2
3
4
5
6
7
8
9
10
11
import process from "node:process";
export const upstashJSONEx = (async () => {
const { Redis } = await import("npm:@upstash/redis");
const redis = new Redis({
url: process.env.upstashURL,
token: process.env.upstashToken,
});
await redis.set("json-ex-1", { a: { b: "nested json" } });
return ((await redis.get("json-ex-1")) as any).a.b;
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import process from "node:process";
export let upstash = async (key: string, value?: any) => {
const { Redis } = await import("npm:@upstash/redis");
const redis = new Redis({
url: process.env.upstashURL,
token: process.env.upstashToken,
});
if (!value) {
return redis.get(key);
}
else {
await redis.set(key, value);
return value;
}
};
1
2
3
4
5
6
7
8
9
10
11
import process from "node:process";
export const upstashEx = (async () => {
const { Redis } = await import("npm:@upstash/redis");
const redis = new Redis({
url: process.env.upstashURL,
token: process.env.upstashToken,
});
console.log(await redis.set("foo", "bar"));
console.log(await redis.get("foo"));
})();
1
Next