feat: added redis
This commit is contained in:
33
lib/cache.ts
Normal file
33
lib/cache.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { connect } from "https://deno.land/x/redis/mod.ts";
|
||||
|
||||
const REDIS_HOST = Deno.env.get("REDIS_HOST");
|
||||
const REDIS_PASS = Deno.env.get("REDIS_PASS");
|
||||
const REDIS_PORT = Deno.env.get("REDIS_PORT");
|
||||
|
||||
async function createCache() {
|
||||
if (REDIS_HOST && REDIS_PASS) {
|
||||
const client = await connect({
|
||||
password: REDIS_PASS,
|
||||
hostname: REDIS_HOST,
|
||||
port: REDIS_PORT || 6379,
|
||||
});
|
||||
console.log("COnnected to redis");
|
||||
return client;
|
||||
}
|
||||
|
||||
return new Map<string, any>();
|
||||
}
|
||||
|
||||
const cache = await createCache();
|
||||
|
||||
export function get(id: string) {
|
||||
return cache.get(id);
|
||||
}
|
||||
|
||||
export function has(id: string) {
|
||||
return cache.has(id);
|
||||
}
|
||||
|
||||
export function set(id: string, content: any) {
|
||||
return cache.set(id, content);
|
||||
}
|
Reference in New Issue
Block a user