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
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.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 TLSREDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.
Redis CLI
Redis CLI
@upstash/redis
@upstash/redis
upstash_redis
upstash_redis
ioredis
ioredis
node-redis
node-redis
redis-py
redis-py
go-redis
go-redis
jedis
jedis
redis-rs
redis-rs