feat: Command Log dialog
- New commandLogger.ts: in-memory log (max 5000 entries) - withLog() wrapper in ipc-handlers.ts for all write commands - CommandLog.vue: table with time/command/duration, write-only filter - IPC: redis:getCommandLog, redis:clearCommandLog - Ctrl+G shortcut from Sidebar - i18n keys (zh-CN + en)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// electron/main/redis/commandLogger.ts
|
||||
// 命令日志记录器
|
||||
|
||||
export interface CommandEntry {
|
||||
id: number
|
||||
time: string
|
||||
connection: string
|
||||
command: string
|
||||
duration: number
|
||||
isWrite: boolean
|
||||
}
|
||||
|
||||
const MAX_ENTRIES = 5000
|
||||
let nextId = 1
|
||||
const entries: CommandEntry[] = []
|
||||
|
||||
const WRITE_COMMANDS = new Set([
|
||||
'SET', 'DEL', 'HSET', 'HDEL', 'RPUSH', 'LPUSH', 'LSET', 'LREM',
|
||||
'SADD', 'SREM', 'ZADD', 'ZREM', 'XADD', 'XDEL', 'XTRIM',
|
||||
'RENAME', 'EXPIRE', 'PERSIST', 'FLUSHDB', 'SELECT',
|
||||
'SETEX', 'INCR', 'DECR', 'INCRBY', 'DECRBY', 'APPEND',
|
||||
'HMSET', 'HINCRBY', 'HINCRBYFLOAT',
|
||||
'LPOP', 'RPOP', 'BLPOP', 'BRPOP',
|
||||
'ZINCRBY', 'ZREMRANGEBYRANK', 'ZREMRANGEBYSCORE',
|
||||
'UNLINK', 'MOVE', 'RENAMENX',
|
||||
])
|
||||
|
||||
export function log(connection: string, command: string, duration: number): void {
|
||||
const isWrite = WRITE_COMMANDS.has(command.split(' ')[0].toUpperCase())
|
||||
entries.push({
|
||||
id: nextId++,
|
||||
time: new Date().toISOString(),
|
||||
connection,
|
||||
command,
|
||||
duration,
|
||||
isWrite,
|
||||
})
|
||||
if (entries.length > MAX_ENTRIES) {
|
||||
entries.splice(0, entries.length - MAX_ENTRIES)
|
||||
}
|
||||
}
|
||||
|
||||
export function getLog(): CommandEntry[] {
|
||||
return entries
|
||||
}
|
||||
|
||||
export function clearLog(): void {
|
||||
entries.length = 0
|
||||
}
|
||||
@@ -9,3 +9,4 @@ export * from './set'
|
||||
export * from './zset'
|
||||
export * from './stream'
|
||||
export * from './server'
|
||||
export * from './commandLogger'
|
||||
|
||||
Reference in New Issue
Block a user