-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feacfd2
commit 45c2621
Showing
14 changed files
with
457 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from "./cache"; | ||
export * from "./error"; | ||
export * from "./pagination"; | ||
export * from "./redis"; | ||
export * from "./search"; | ||
export * from "./sort"; | ||
export * from "./superjson"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Redis } from "@upstash/redis"; | ||
import { Cache, CacheEntry } from "cachified"; | ||
|
||
import { KV_STORE_REST_API_URL } from "../env"; | ||
import { KV_STORE_REST_API_TOKEN } from "../env"; | ||
|
||
const DEFAULT_TTL = 1000 * 60 * 60 * 24 * 7; | ||
|
||
export function getRedisClient() { | ||
return new Redis({ | ||
url: KV_STORE_REST_API_URL!, | ||
token: KV_STORE_REST_API_TOKEN!, | ||
}); | ||
} | ||
|
||
export const redisKvStoreAdapter = (store: Redis): Cache => ({ | ||
set: <T>(key: string, value: CacheEntry<T>) => { | ||
value.metadata.ttl; | ||
return store.set(key, value, { | ||
px: value.metadata.ttl ?? DEFAULT_TTL, | ||
}); | ||
}, | ||
get: <T>(key: string) => { | ||
return store.get<T>(key); | ||
}, | ||
delete: (key) => { | ||
return store.del(key); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.