user3198603
user3198603

Reputation: 5836

Key and field in redis?

Here is the Redis doc says about Hash HSET command

    Redis HSET command is used to set field in the hash stored at the key to value.

Command

  HSET KEY_NAME FIELD VALUE

Example

    HSET user:A:address  city NY

I believe user:A:address is the hashmap name , city is the key and NY is the value. Right ?

Actually above doc(HSET KEY_NAME FIELD VALUE) mentions hashmap name as key and key as field. So bit confused

Upvotes: 2

Views: 4075

Answers (2)

sourabh1024
sourabh1024

Reputation: 657

Redis Hash is generally used to store fields and values related to a key. We can store multiple keys in Redis hash.

For example : Lets consider we want to store the username , email_id , contact_no and other fields of a user. We can use userId as key in Redis hash and username, emailid , contact_no as fields and their corresponding values as values.

Key : userId (1234)
Field : username  Value : test
Field : emailid Value : [email protected]
Field : contact_no Value : 1234567890

Similarly we can store required fields for all users using a unique key ( userID in this example)

Upvotes: 2

Itamar Haber
Itamar Haber

Reputation: 50102

user:A:address is the key name (KEY_NAME) in the Redis keyspace, which in your example is of type Hash. city is the field name inside that Hash, and NY is that field's value.

Using the doc and replacing the terms with your example's values:

Redis HSET command is used to set city in the hash stored at user:A:address to NY.

Upvotes: 2

Related Questions