Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between HSET and HMSET method in redis database

Tags:

database

redis

In my application im using redis database.I have gone through their documentation but i couldn't find the difference between HSET and HMSET.

like image 308
sachin Avatar asked Mar 07 '13 06:03

sachin


People also ask

What is Hmset in Redis?

Redis HMSET command is used to set the specified fields to their respective values in the hash stored at the key. This command overwrites any existing fields in the hash. If the key does not exist, a new key holding a hash is created.

What does HSET do in Redis?

Redis HSET command is used to set field in the hash stored at the key to value. If the key does not exist, a new key holding a hash is created. If the field already exists in the hash, it is overwritten.

What is HSET?

Acronym. Definition. HSET. Health, Safety and Environmental Technology (various universities)

Is Hmset deprecated?

HMSET key field value [ field value ...]As of Redis version 4.0. 0, this command is regarded as deprecated. It can be replaced by HSET with multiple field-value pairs when migrating or writing new code.


2 Answers

HSET used to be able to set only one key-value pair. And if you needed to set several at once, you would have to use HMSET (M for multi). That was changed a few years ago, to allow both commands to accept multiple pairs. And now HMSET is redundant.

From official documentation:

As per Redis 4.0.0, HMSET is considered deprecated. Please use HSET in new code.

like image 196
Sergio Tulentsev Avatar answered Sep 19 '22 20:09

Sergio Tulentsev


HSET key field value:

Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

HMSET key field value [field value ...]

Sets the specified fields to their respective values in the hash stored at key. This command overwrites any existing fields in the hash. If key does not exist, a new key holding a hash is created.

For more redis commands information, click here.

like image 35
Hrishikesh Mishra Avatar answered Sep 19 '22 20:09

Hrishikesh Mishra