mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 14:14:06 +00:00
starting caching work
This commit is contained in:
27
config/redis.ts
Normal file
27
config/redis.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { createClient } from "redis";
|
||||
|
||||
import curriedLogger from "../utils/logger.ts";
|
||||
import { sleep } from "../utils/flake.ts";
|
||||
const logger = curriedLogger(import.meta.filename);
|
||||
|
||||
if (!process.env["REDIS_URI"])
|
||||
throw new TypeError("Redis connection URI not defined");
|
||||
|
||||
// Initialize
|
||||
const redisClient: ReturnType<typeof createClient> = createClient({
|
||||
url: process.env["REDIS_URI"],
|
||||
});
|
||||
|
||||
// Check connection
|
||||
(async () => {
|
||||
try {
|
||||
await redisClient.connect();
|
||||
while (!redisClient.isReady) await sleep(100);
|
||||
logger.info("Connected to Redis store");
|
||||
} catch (error) {
|
||||
logger.error("Redis connection error", { error });
|
||||
throw error;
|
||||
}
|
||||
})();
|
||||
|
||||
export { redisClient };
|
||||
Reference in New Issue
Block a user