Skip to content

Commit

Permalink
remove export and save the client
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Mar 7, 2024
1 parent bb1deb0 commit 63d0f21
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions app/api/auth/[...nextauth]/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import CredentialsProvider from "next-auth/providers/credentials"
import { AuthOptions, User } from "next-auth"


export const connections = new Map<number, RedisClientType>();
const connections = new Map<number, RedisClientType>();

export async function getConnection(user: User) {
return connections.get(user.id) ?? await createClient({
socket: {
host: user.host ?? "localhost",
port: user.port ?? 6379,
reconnectStrategy: false
},
password: user.password ?? undefined,
username: user.username ?? undefined
})
let conn = connections.get(user.id)
if (!conn) {
conn = await createClient({
socket: {
host: user.host ?? "localhost",
port: user.port ?? 6379,
reconnectStrategy: false
},
password: user.password ?? undefined,
username: user.username ?? undefined
})
connections.set(user.id, conn)
}
return conn
}

let userId = 1;
Expand Down

0 comments on commit 63d0f21

Please sign in to comment.