Upstash Documentation

HSET

Set hash field values.
2 min read

Use HSET to set one or more fields of a hash to the given values, creating the key when it does not exist.

Existing fields are overwritten, and the reply counts only the fields that were added, not those that were updated, which is how you tell an insert from an update. Setting fields does not touch the key's time to live, so a hash with an expiration keeps it as it is written to. A field's own expiration is a different matter: writing a field clears the TTL it may have been given by HEXPIRE or HSETEX.

Hashes are the compact way to store an object under one key: field access with HSET and HGET avoids reading and rewriting the whole value the way a serialized string would.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesNoRedis key targeted by the command.
<field> <value>YesYesField and the value to store in it. Repeat to set several fields in one call.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Integer
RESP3Integer
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs