Files
JRedisDesktop/electron/redis/string.ts
T
2026-07-10 23:05:10 +08:00

35 lines
1.2 KiB
TypeScript

// src/main/redis/string.ts
// String + ReJson 操作
import { getClient } from './connection'
export async function getStringValue(id: string, key: string): Promise<string | null> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return client.get(key)
}
export async function setStringValue(id: string, key: string, value: string): Promise<void> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
await client.set(key, value)
}
// ReJson operations
export async function rejsonGet(id: string, key: string, path: string = '.'): Promise<string> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return (client as any).call('JSON.GET', key, path)
}
export async function rejsonSet(id: string, key: string, path: string, value: string): Promise<void> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
await (client as any).call('JSON.SET', key, path, value)
}
export async function rejsonDel(id: string, key: string, path: string = '.'): Promise<number> {
const client = getClient(id)
if (!client) throw new Error(`Client ${id} not found`)
return (client as any).call('JSON.DEL', key, path)
}