Usage
Sets the specified fields to their respective values in the hash stored atkey. 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
The key of the hash
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
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 (unlikeHSETwhich returns the count) - As of Redis 4.0.0, this command is deprecated in favor of
HSET HSETcan accept multiple field-value pairs and has the same behavior asHMSET- The command overwrites existing fields
- If the key does not exist, a new hash is created
- Consider using
HSETfor new implementations
Migration Guide
ReplaceHMSET with HSET in your code:
HMSETreturns'OK'HSETreturns the number of fields added/updated