Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
sj817 committed Jan 16, 2025
1 parent ac0be5f commit 5fda871
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions packages/core/src/core/db/redis/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import moment from 'moment'
import { EventEmitter } from 'node:events'
import { redisLevelPath } from '@/root'
import { existToMkdirSync } from '@/utils/fs/fsSync'
import type { SetOptions } from 'redis'

/**
* @description 键类型枚举
Expand Down Expand Up @@ -52,7 +51,7 @@ export class RedisClient extends EventEmitter {
/** 位图 */
#bit: Record<string, Buffer> = {}
/** 持久化数据库 */
#level!: Level<string, string>
#level!: Level

constructor () {
super()
Expand All @@ -65,7 +64,6 @@ export class RedisClient extends EventEmitter {
this.#zset = {}
this.#pf = {}
this.#bit = {}
process.once('exit', () => this.#level.close())
}

async init () {
Expand All @@ -81,7 +79,7 @@ export class RedisClient extends EventEmitter {
setInterval(() => this.save(), 120000)

const list = await this.#level.keys().all()
await Promise.all(list.map(async (key) => {
await Promise.all(list.map(async (key: string) => {
const data = await this.#level.get(key).catch(() => null)
if (!data) return
const { type, expire, value } = JSON.parse(data)
Expand Down Expand Up @@ -220,7 +218,7 @@ export class RedisClient extends EventEmitter {
* @param value 值
* @param options 其他参数
*/
async set (key: string, value: string | Buffer, options: SetOptions = {}): Promise<string | Buffer | null> {
async set (key: string, value: string | Buffer, options: any = {}): Promise<string | Buffer | null> {
/*
| **参数** | **对应 Redis 原生选项** | **作用** | **说明** |
|----------------|-------------------------|-------------------------------------|------------------------------------------|
Expand Down Expand Up @@ -929,11 +927,11 @@ export class RedisClient extends EventEmitter {
async save (): Promise<string> {
/** 读取keys 排除掉不是重复项的键 */
const keys = await this.#level.keys().all()
const delKeys = keys.filter((key) => !this.#info[key])
const delKeys = keys.filter((key: string) => !this.#info[key])
const list: Array<{ type: 'put', key: string, value: string } | { type: 'del', key: string }> = []

delKeys.forEach((key) => list.push({ type: 'del', key }))
Object.keys(this.#info).forEach((key) => {
delKeys.forEach((key: string) => list.push({ type: 'del', key }))
Object.keys(this.#info).forEach((key: string) => {
const { type, expire } = this.#info[key]
const value = this.#str[key]
list.push({ type: 'put', key, value: JSON.stringify({ type, expire, value }) })
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/db/redis/redis.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'os'
import { RedisClient } from '@/core/db/redis/mock'
import { createClient, RedisClientOptions, RedisClientType } from 'redis'
import { createClient, RedisClientType, RedisClientOptions } from 'redis'
import { isWin } from '@/env'
import { exec } from '@/utils/system/exec'
import { redis } from '@/utils/config'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/internal/listeners.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: 此文件存在内存泄漏 可能是无限循环引用导致的
import { EventEmitter } from 'events'
import { EventEmitter } from 'node:events'
import type { MessageEventMap, NoticeEventMap, RequestEventMap } from '@/types/event'

// type OtherTypes = {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"resolveJsonModule": true,
"rootDir": "./src",
"skipLibCheck": true,
"skipLibCheck": false,
"sourceMap": false,
"strict": true,
"target": "ES2022",
Expand All @@ -43,4 +43,4 @@
"resolveFullExtension": ".js",
"resolveFullPaths": true
}
}
}

0 comments on commit 5fda871

Please sign in to comment.