Skip to main content

Usage

Sets the specified fields to their respective values in the hash stored at key. This command overwrites any specified fields already existing in the hash.
As of Redis 4.0.0, HMSET is considered deprecated. Use HSET with multiple field-value pairs instead, which has the same behavior.

Parameters

key
string
required
The key of the hash
fieldValueObject
Record<string, TData>
required
An object containing field-value pairs to set in the hash. Each key in the object represents a field name, and its value is the value to set.

Response

status
'OK'
Always returns 'OK' when successful.

Examples

Set multiple fields

Update existing fields

Initialize configuration

Store session data

Migrate from HMSET to HSET

Bulk insert user data

Set default values

Notes

  • Always returns 'OK' on success (unlike HSET which returns the count)
  • As of Redis 4.0.0, this command is deprecated in favor of HSET
  • HSET can accept multiple field-value pairs and has the same behavior as HMSET
  • The command overwrites existing fields
  • If the key does not exist, a new hash is created
  • Consider using HSET for new implementations

Migration Guide

Replace HMSET with HSET in your code:
The main difference is the return value:
  • HMSET returns 'OK'
  • HSET returns the number of fields added/updated

See Also

  • HSET - Set hash field values (recommended)
  • HGET - Get a hash field value
  • HMGET - Get multiple hash field values
  • HGETALL - Get all fields and values in a hash