我有一個包含discord欄位的架構,它存盤用戶不和諧的用戶 ID。
如果現有密鑰都不匹配我要創建的密鑰,我想創建一個 JSON 密鑰discord,但更新該discord欄位匹配的密鑰。我正在為 Node.js 使用 Redis OM,但幾乎沒有任何檔案清楚地告訴我我能做什么。
這是我當前的代碼
export async function createStudent(data: StudentData): Promise<string> {
await connect();
const repository = client.fetchRepository(schema);
const student = repository.createEntity(data);
const id = await repository.save(student);
await client.execute(["EXPIRE", `Student:${id}`, 60]);
return id;
}
uj5u.com熱心網友回復:
Redis 中沒有內置功能可以執行此操作,但您可以撰寫自定義腳本來執行此操作。像這樣的東西:
if (redis.exists(key)) {
redis.hset(key, field, value);
} else {
redis.hset(key, field, value);
redis.expire(key, 60);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/516230.html
標籤:节点.js打字稿雷迪斯
上一篇:打字稿事件發射器型別
下一篇:檔案未在事件目標上退出
