// Hash 操作 import { getClient } from './connection' export async function getHashFields( id: string, key: string, cursor: string, count: number ): Promise<{ cursor: string; fields: [string, string][] }> { const client = getClient(id) if (!client) throw new Error(`Client ${id} not found`) const [nextCursor, raw] = await client.hscan(key, cursor, 'COUNT', count) const fields: [string, string][] = [] for (let i = 0; i < raw.length; i += 2) { fields.push([raw[i], raw[i + 1]]) } return { cursor: nextCursor, fields } } export async function setHashField( id: string, key: string, field: string, value: string ): Promise { const client = getClient(id) if (!client) throw new Error(`Client ${id} not found`) await client.hset(key, field, value) } export async function deleteHashField(id: string, key: string, field: string): Promise { const client = getClient(id) if (!client) throw new Error(`Client ${id} not found`) await client.hdel(key, field) }