> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HSETNX

> Write a field to a hash but only if the field does not exist.

## Arguments

<ParamField body="key" type="string" required>
  The key of the hash.
</ParamField>

<ParamField body="field" type="string" required>
  The name of the field.
</ParamField>

<ParamField body="value" type="TValue" required>
  Any value, if it's not a string it will be serialized to JSON.
</ParamField>

## Response

<ResponseField type="integer" required>
  `1` if the field was set, `0` if it already existed.
</ResponseField>

<RequestExample>
  ```ts Example theme={"system"}
  await redis.hsetnx("key", "id", 1)
  ```
</RequestExample>
