Files
JRedisDesktop/electron/redis/stream.ts
T
Jokul 157af4399f fix: 修复文件层级重构后的架构问题
- 恢复 IPC 类型声明 (src/electron-api.d.ts),修复 31 个 TS2339 错误
- 修复构建断裂:vite.config.ts 改回 electron.vite.config.ts
- 修复 2 个 verbatimModuleSyntax type-import 报错
- 修正 .gitignore 构建产物路径 (electron-dist/ -> dist-electron/ + release/)
- 清理 55+ 处过时路径注释
- 更新 AGENTS.md 架构文档与 IPC 通道表
- 修正 docs/ROADMAP.md 过时引用
2026-07-10 23:22:53 +08:00

72 lines
2.6 KiB
TypeScript

// Stream 操作
import { getClient } from './connection'
export async function streamInfo(id: string, key: string): Promise<any> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xinfo('STREAM', key)
}
export async function streamRange(
id: string, key: string, start: string, end: string, count: number
): Promise<any[]> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xrange(key, start, end, 'COUNT', count)
}
export async function streamAdd(
id: string, key: string, streamId: string, fieldValues: string[]
): Promise<string | null> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xadd(key, streamId, ...fieldValues)
}
export async function streamTrim(id: string, key: string, maxLen: number): Promise<number> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xtrim(key, 'MAXLEN', maxLen)
}
export async function streamDel(id: string, key: string, ...ids: string[]): Promise<number> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xdel(key, ...ids)
}
// Consumer group operations
export async function streamGroups(id: string, key: string): Promise<any[]> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xinfo('GROUPS', key) as Promise<any[]>
}
export async function streamConsumers(id: string, key: string, group: string): Promise<any[]> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.xinfo('CONSUMERS', key, group) as Promise<any[]>
}
export async function streamGroupCreate(
id: string, key: string, group: string, startId: string, mkstream: boolean
): Promise<string> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
const args: any[] = [key, group, startId]
if (mkstream) args.push('MKSTREAM')
return (client as any).xgroup('CREATE', ...args)
}
export async function streamGroupDestroy(id: string, key: string, group: string): Promise<number> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return (client as any).xgroup('DESTROY', key, group)
}
export async function streamAck(id: string, key: string, group: string, ...ids: string[]): Promise<number> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return (client as any).xack(key, group, ...ids)
}