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/
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
// src/main/redis/zset.ts
|
|
// Sorted Set 操作
|
|
import { getClient } from './connection'
|
|
|
|
export async function zsetRange(id: string, key: string, start: number, stop: number, withScores: boolean): Promise<string[]> {
|
|
const client = getClient(id)
|
|
if (!client) throw new Error(`Client ${id} not found`)
|
|
if (withScores) return client.zrange(key, start, stop, 'WITHSCORES')
|
|
return client.zrange(key, start, stop)
|
|
}
|
|
|
|
export async function zsetSize(id: string, key: string): Promise<number> {
|
|
const client = getClient(id)
|
|
if (!client) throw new Error(`Client ${id} not found`)
|
|
return client.zcard(key)
|
|
}
|
|
|
|
export async function zsetAdd(id: string, key: string, score: number, member: string): Promise<number> {
|
|
const client = getClient(id)
|
|
if (!client) throw new Error(`Client ${id} not found`)
|
|
return client.zadd(key, score, member)
|
|
}
|
|
|
|
export async function zsetRemove(id: string, key: string, ...members: string[]): Promise<number> {
|
|
const client = getClient(id)
|
|
if (!client) throw new Error(`Client ${id} not found`)
|
|
return client.zrem(key, ...members)
|
|
}
|