Fixed redis issues
This commit is contained in:
@@ -12,7 +12,7 @@ export function GET(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function UPGRADE(client: WebSocket, server: WebSocketServer) {
|
export function UPGRADE(client: WebSocket, server: WebSocketServer) {
|
||||||
const subscriber = new Redis();
|
const subscriber = new Redis(process.env.REDIS_URL!);
|
||||||
let runId: string;
|
let runId: string;
|
||||||
|
|
||||||
client.once("message", async (message) => {
|
client.once("message", async (message) => {
|
||||||
@@ -59,7 +59,7 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.once("close", async () => {
|
client.once("close", async () => {
|
||||||
if (runId) await subscriber.unsubscribe(`liveRun:${runId}`);
|
await subscriber.unsubscribe(`liveRunEvent:${runId}`);
|
||||||
subscriber.quit();
|
subscriber.quit();
|
||||||
await updateLiveRunViews(runId, -1);
|
await updateLiveRunViews(runId, -1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ export async function addLiveRunEvent(
|
|||||||
language: string,
|
language: string,
|
||||||
moves: LiveRunMove[],
|
moves: LiveRunMove[],
|
||||||
) {
|
) {
|
||||||
const redis = new Redis();
|
|
||||||
|
|
||||||
// Make sure the live run exists
|
// Make sure the live run exists
|
||||||
const runExists = await redis.exists(`liveRun:${runId}`);
|
const runExists = await redis.exists(`liveRun:${runId}`);
|
||||||
if (!runExists) throw "Invalid live run";
|
if (!runExists) throw "Invalid live run";
|
||||||
|
|||||||
Reference in New Issue
Block a user