redis not req for local dev

This commit is contained in:
PxlLoewe
2025-10-04 21:58:34 +02:00
parent a2c320ddbe
commit 1919227cd4
3 changed files with 13 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
DISPATCH_SERVER_PORT=3002 DISPATCH_SERVER_PORT=3002
REDIS_HOST=localhost REDIS_HOST=localhost
REDIS_PORT=6379 REDIS_PORT=6379
CORE_SERVER_URL=http://core-server CORE_SERVER_URL=http://localhost:3005
DISPATCH_APP_TOKEN=dispatch DISPATCH_APP_TOKEN=dispatch
LIVEKIT_API_KEY=APIAnsGdtdYp2Ho LIVEKIT_API_KEY=APIAnsGdtdYp2Ho
LIVEKIT_API_SECRET=tdPjVsYUx8ddC7K9NvdmVAeLRF9GeADD6Fedm1x63fWC LIVEKIT_API_SECRET=tdPjVsYUx8ddC7K9NvdmVAeLRF9GeADD6Fedm1x63fWC

View File

@@ -18,7 +18,10 @@ const app = express();
const server = createServer(app); const server = createServer(app);
export const io = new Server(server, { export const io = new Server(server, {
adapter: createAdapter(pubClient, subClient), adapter:
process.env.REDIS_HOST && process.env.REDIS_PORT
? createAdapter(pubClient, subClient)
: undefined,
cors: {}, cors: {},
}); });
io.use(jwtMiddleware); io.use(jwtMiddleware);

View File

@@ -1,13 +1,17 @@
import { createClient, RedisClientType } from "redis"; import { createClient, RedisClientType } from "redis";
export const pubClient: RedisClientType = createClient({ export const pubClient: RedisClientType = createClient({
url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`, url: `redis://${process.env.REDIS_HOST || "localhost"}:${process.env.REDIS_PORT || 6379}`,
}); });
export const subClient: RedisClientType = pubClient.duplicate(); export const subClient: RedisClientType = pubClient.duplicate();
Promise.all([pubClient.connect(), subClient.connect()]).then(() => { if (!process.env.REDIS_HOST || !process.env.REDIS_PORT) {
console.log("Redis connected"); console.warn("REDIS_HOST or REDIS_PORT not set, skipping Redis connection");
}); } else {
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
console.log("Redis connected");
});
}
pubClient.on("error", (err) => console.log("Redis Client Error", err)); pubClient.on("error", (err) => console.log("Redis Client Error", err));
subClient.on("error", (err) => console.log("Redis Client Error", err)); subClient.on("error", (err) => console.log("Redis Client Error", err));