bdcf4fe299
- Move main process to electron/main/ - Move preload to electron/preload/ - Add shared types in electron/shared/ - Split redis-service into modular redis/ directory - Flatten renderer to src/ (remove src/renderer/ nesting) - Update electron.vite.config.ts paths - Update tsconfig paths - Output to electron-dist/
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
// src/main/redis/stream.ts
|
|
// 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)
|
|
}
|