Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/drivers/redis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ export class RedisDriver implements Driver {
};

const key = this.generateRedisKey(objectName, id);
await this.client.set(key, JSON.stringify(doc));

// Use SET with NX option to prevent overwriting existing records
const result = await this.client.set(key, JSON.stringify(doc), { NX: true });

if (!result) {
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SET with NX typically returns 'OK' on success and null on failure (duplicate). Using if (!result) works, but it’s clearer/safer to check explicitly for the expected failure value (e.g., result === null) or success value (e.g., result !== 'OK') to avoid any ambiguity if return types change across Redis clients.

Suggested change
if (!result) {
if (result === null) {

Copilot uses AI. Check for mistakes.
throw new Error(`Record with ID ${id} already exists in ${objectName}`);
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing a plain Error makes it harder for callers (and cross-driver behavior) to reliably detect a duplicate-ID condition. If the project has a standard duplicate/constraint error type or error code used by other drivers, throw that here (or wrap with a distinct name/code) so consumers can handle duplicates consistently without parsing the message.

Copilot uses AI. Check for mistakes.
}

return doc;
}
Expand Down