-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add state to server selector and redis
- Loading branch information
1 parent
f3f54c6
commit 624157f
Showing
13 changed files
with
145 additions
and
38 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use server"; | ||
|
||
import { Redis } from "@upstash/redis"; | ||
|
||
import { env } from "@/env"; | ||
|
||
const redis = new Redis({ | ||
url: env.REDIS_URI, | ||
token: env.REDIS_TOKEN, | ||
}); | ||
|
||
export interface getOptions { | ||
force?: boolean; | ||
} | ||
export async function get<T>( | ||
key: string, | ||
options?: getOptions, | ||
): Promise<T | null> { | ||
if (env.DISABLE_CACHING === true && !options?.force) return null; | ||
const value = await redis.get(key); | ||
if (!value) return null; | ||
return value as T; | ||
} | ||
|
||
export interface setOptions { | ||
ttl?: number; // in seconds | ||
force?: boolean; | ||
} | ||
|
||
export async function set<T>( | ||
key: string, | ||
value: T, | ||
options?: setOptions, | ||
): Promise<void> { | ||
if (env.DISABLE_CACHING === true && !options?.force) return; | ||
await redis.set( | ||
key, | ||
JSON.stringify(value), | ||
options?.ttl ? { ex: options?.ttl } : { ex: 300 }, | ||
); | ||
} | ||
|
||
export interface delOptions { | ||
force?: boolean; | ||
} | ||
|
||
export async function del(key: string, options?: delOptions): Promise<void> { | ||
if (env.DISABLE_CACHING === true && !options?.force) return; | ||
await redis.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