HSET command in redis

HSET key field value

Set the specified hash field to the specified value. If the key does not exist, a new key holding a hash is created.

If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.

TIME COMPLEXITY: O(1) 

RETURN VALUE: It returns an integer reply.

Syntax:

HSET KEY_NAME FIELD_NAME VALUE

Example 1: When the key is not present.

redis:6379> HSET myRedisKey field 100
(integer) 1

Output

1


Example 2: When the key is present.

redis:6379> HSET myRedisKey field 200
(integer) 0

Output

0


No comments:

Post a Comment