Typing redis
This commit is contained in:
parent
6879c65a5b
commit
9cd7ef7827
|
@ -120,7 +120,7 @@ export async function getUsers(
|
|||
): Promise<{ users: User[]; notFoundIds?: string[] }> {
|
||||
const client = await redis.getUserClient()
|
||||
// try cache
|
||||
let usersFromCache = await client.bulkGet(userIds)
|
||||
let usersFromCache = await client.bulkGet<User>(userIds)
|
||||
const missingUsersFromCache = userIds.filter(uid => !usersFromCache[uid])
|
||||
const users = Object.values(usersFromCache)
|
||||
let notFoundIds
|
||||
|
|
|
@ -242,7 +242,7 @@ class RedisWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
async bulkGet(keys: string[]) {
|
||||
async bulkGet<T>(keys: string[]) {
|
||||
const db = this._db
|
||||
if (keys.length === 0) {
|
||||
return {}
|
||||
|
@ -250,7 +250,7 @@ class RedisWrapper {
|
|||
const prefixedKeys = keys.map(key => addDbPrefix(db, key))
|
||||
let response = await this.getClient().mget(prefixedKeys)
|
||||
if (Array.isArray(response)) {
|
||||
let final: Record<string, any> = {}
|
||||
let final: Record<string, T> = {}
|
||||
let count = 0
|
||||
for (let result of response) {
|
||||
if (result) {
|
||||
|
|
|
@ -150,7 +150,7 @@ export class BaseSocket {
|
|||
if (room) {
|
||||
const sessionIds = await this.getRoomSessionIds(room)
|
||||
const keys = sessionIds.map(this.getSessionKey.bind(this))
|
||||
const sessions = await this.redisClient?.bulkGet(keys)
|
||||
const sessions = await this.redisClient?.bulkGet<SocketSession>(keys)
|
||||
return Object.values(sessions || {})
|
||||
} else {
|
||||
return []
|
||||
|
|
Loading…
Reference in New Issue