content/commands/hsetnx.md
Sets field in the hash stored at key to value, only if field does not
yet exist.
If key does not exist, a new key holding a hash is created.
If field already exists, this operation has no effect.
{{% redis-cli %}} HSETNX myhash field "Hello" HSETNX myhash field "World" HGET myhash field {{% /redis-cli %}}
| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |
{{< multitabs id="hsetnx-return-info" tab1="RESP2" tab2="RESP3" >}}
One of the following:
0 if the field already exists in the hash and no operation was performed.1 if the field is a new field in the hash and the value was set.-tab-sep-
One of the following:
0 if the field already exists in the hash and no operation was performed.1 if the field is a new field in the hash and the value was set.{{< /multitabs >}}