| 1 | /** |
| 2 | * vinext data-cache adapter builder for Redis. |
| 3 | * |
| 4 | * Node Website.Vinext resources inject this adapter automatically. |
| 5 | * The runtime factory uses {@link connect} from `alchemy/Redis` (the same |
| 6 | * client Fly/Railway `*RedisHttp` layers use) and reads `REDIS_URL` |
| 7 | * (or `urlEnv`) from the process environment. |
| 8 | * |
| 9 | * Pair with `Railway.Redis` / `Fly.Redis` so the Website host gets |
| 10 | * `REDIS_URL`. Missing URL (local `vinext start` / `alchemy dev`) makes |
| 11 | * vinext log and fall back to the in-memory handler. |
| 12 | */ |
| 13 | import { fileURLToPath } from "node:url"; |
| 14 | import type { RedisAdapterOptions } from "./redis-runtime.ts"; |
| 15 | |
| 16 | export type { RedisAdapterOptions } from "./redis-runtime.ts"; |
| 17 | |
| 18 | export const DEFAULT_REDIS_URL_ENV = "REDIS_URL"; |
| 19 | |
| 20 | export const redisAdapter = (options?: RedisAdapterOptions) => { |
| 21 | if (options?.urlEnv !== undefined && typeof options.urlEnv !== "string") { |
| 22 | throw new TypeError( |
| 23 | "[vinext] redisAdapter({ urlEnv }) must be a string env var name.", |
| 24 | ); |
| 25 | } |
| 26 | return { |
| 27 | adapter: fileURLToPath(new URL("./redis-runtime.js", import.meta.url)), |
| 28 | options, |
| 29 | }; |
| 30 | }; |