HSET

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Set a field and value

The usage is hset key field value.
You can store multiple fields and values in a key. If the same field already exists, it is overwritten.
The structure is similar to a relational database table. However, fields can differ per key.

Example

Command>hset user-1 email charlie@redisgate.com
Result>1
Command>hset user-1 language english
Result>1
Command>hset user-1 gender m
Result>1
Command>hgetall user-1
Result> 0) email -> charlie@redisgate.com
1) language -> english
2) gender -> m

View animation

When you run hgetall, redis-cli shows the field and value on separate lines, whereas Redis Web Client shows them on one line in field -> value form as in the result above.

From version 4.0.0 you can specify multiple fields and values.

From version 4.0.0, using hset instead of hmset is recommended.

Example

Command>hset myhash f1 v1 f2 v2
Result>2

Syntax

HSET key field value [field value ...]

  • Available since version 2.0.0.
  • Time complexity is O(1).
SQL Insert If you are on Redis Enterprise 7.3.0 or later, try INSERT.
Related commands HMSET, HDEL, SET, LPUSH, SADD, ZSET
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< HASHES Introduction HSET HSETS >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.