Skip to content

fix: add hSetNX to Redis transaction interface#248

Open
mvanhorn wants to merge 1 commit intoreddit:mainfrom
mvanhorn:osc/184-hsetnx-missing-from-transactions
Open

fix: add hSetNX to Redis transaction interface#248
mvanhorn wants to merge 1 commit intoreddit:mainfrom
mvanhorn:osc/184-hsetnx-missing-from-transactions

Conversation

@mvanhorn
Copy link

Summary

Adds hSetNX to the Redis transaction interface (TxClientLike) and both transaction class implementations. The method exists in the non-transaction RedisClient but was missing from transactions.

Why this matters

#184 reports that hSetNX is unavailable in transactions. The TxClientLike type has hSet, hGet, hMGet, hGetAll, hDel, hScan, hKeys, hIncrBy, and hLen but not hSetNX. This makes it impossible to use atomic hash-set-if-not-exists operations within Redis transactions.

Changes

  • packages/redis/src/types/redis.ts - Added hSetNX to TxClientLike type
  • packages/redis/src/RedisClient.ts - Added hSetNX to the transaction class, following the same pattern as hSet (queue with transactionId, return this)
  • packages/public-api/src/apis/redis/RedisClient.ts - Added hSetNX and lowercase hsetnx alias to the public-api transaction class, matching the alias pattern used by hset/hSet, hincrby/hIncrBy, etc.

Testing

The implementation follows the exact pattern of existing hash methods in the transaction classes. No new test infrastructure was needed - the method signature and behavior matches the non-transaction hSetNX (queuing the command with transactionId instead of scope).

Fixes #184

This contribution was developed with AI assistance (Claude Code + Codex CLI).

Fixes reddit#184

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mvanhorn mvanhorn requested a review from a team as a code owner March 18, 2026 19:34
@gunsch gunsch requested a review from logan March 18, 2026 20:28
@stephenoid
Copy link
Member

@mvanhorn, would you please sign our contributor agreement?

@mvanhorn
Copy link
Author

Signed the CLA.

@niedzielski
Copy link
Contributor

thanks! i'll try to merge this monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

hSetNX is not available in transactions

5 participants