From 39fc94c6ebfe0a09e552163331fe5110dee985ee Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 18 Mar 2026 12:33:36 -0700 Subject: [PATCH] fix: add hSetNX to Redis transaction interface Fixes #184 Co-Authored-By: Claude Opus 4.6 --- packages/public-api/src/apis/redis/RedisClient.ts | 12 ++++++++++++ packages/redis/src/RedisClient.ts | 8 ++++++++ packages/redis/src/types/redis.ts | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/public-api/src/apis/redis/RedisClient.ts b/packages/public-api/src/apis/redis/RedisClient.ts index 9f819fca..8ac6f2fc 100644 --- a/packages/public-api/src/apis/redis/RedisClient.ts +++ b/packages/public-api/src/apis/redis/RedisClient.ts @@ -354,6 +354,18 @@ export class TxClient implements TxClientLike { return this; } + async hsetnx(key: string, field: string, value: string): Promise { + return this.hSetNX(key, field, value); + } + + async hSetNX(key: string, field: string, value: string): Promise { + await this.#storage.HSetNX( + { key, field, value, transactionId: this.#transactionId }, + this.#metadata + ); + return this; + } + async hincrby(key: string, field: string, value: number): Promise { return this.hIncrBy(key, field, value); } diff --git a/packages/redis/src/RedisClient.ts b/packages/redis/src/RedisClient.ts index 38463d45..5b93a37b 100644 --- a/packages/redis/src/RedisClient.ts +++ b/packages/redis/src/RedisClient.ts @@ -314,6 +314,14 @@ export class TxClient implements TxClientLike { return this; } + async hSetNX(key: string, field: string, value: string): Promise { + await this.#plugin.HSetNX( + { key, field, value, transactionId: this.#transactionId }, + this.#metadata + ); + return this; + } + async hIncrBy(key: string, field: string, value: number): Promise { await this.#plugin.HIncrBy( { key, field, value, transactionId: this.#transactionId }, diff --git a/packages/redis/src/types/redis.ts b/packages/redis/src/types/redis.ts index 8068f5db..8e2d4d89 100644 --- a/packages/redis/src/types/redis.ts +++ b/packages/redis/src/types/redis.ts @@ -573,8 +573,9 @@ export type TxClientLike = { * console.log("Number of fields added: " + numFieldsAdded); * } * ``` - */ + */ hSet(key: string, fieldValues: { [field: string]: string }): Promise; + hSetNX(key: string, field: string, value: string): Promise; /** * Returns the value associated with field in the hash stored at key. * https://redis.io/commands/hget