Redis's hash operation

Source: Internet
Author: User
Tags delete key

Hset key field value function: Set the values of the filed field in key to value note: If there is no field field, add directly, if any, overwrite the value of the original Field field
127.0.0.1:6379> Hset user1 name Lisi
(integer) 1
127.0.0.1:6379> Hset User1 Age 28
(integer) 1
127.0.0.1:6379> hset User1 height 175
(integer) 1
Hmset key field1 value1 [field2 value2 field3 value3 ... fieldn Valuen] Function: Set field1->n field, corresponding value is value1->n (corresponding to PHP understood as  $key = Array (file1=>value1, field2=>value2 .... fieldn=>valuen)) \
127.0.0.1:6379> hmset user2 name Wangwu Age height 160
Ok
Hget key Field action: Returns the value of the Field field in key
127.0.0.1:6379> Hget user1 Name
"Lisi"
Hmget key field1 field2 fieldn function: Returns the value of the Field1 field2 fieldn field in key
127.0.0.1:6379> Hmget User1 name age
1) "Lisi"
2) "28"
Hgetall key function: Returns key, all fields and their values
127.0.0.1:6379> Hgetall User1
1) "Name"
2) "Lisi"
3) "Age"
4) "28"
5) "Height"
6) "175"
 hdel key field action: Delete key in field field 
127.0.0.1:6379 > Hgetall user1
1) "name"
2) " Lisi "

4) "+"
5) "height"
6 "175"
127.0.0.1:6379> Hdel user1 age
(integer) 1
127.0.0.1:6379> Hgetall user1
1) "name"
2) "Lisi"
3) "height"
4) "175"
Hlen key function: Returns the number of elements in key
127.0.0.1:6379> Hlen User1
(integer) 2
127.0.0.1:6379> Hlen User2
(integer) 3
Hexists key field function: Determine if there is a field field in key
127.0.0.1:6379> Hexists user1 Age
(integer) 0
127.0.0.1:6379> hexists user1 Name
(integer) 1
Hincrby key field value action: is to increment the values of the field field in key to integer value
127.0.0.1:6379> Hincrby User2 age 10
(integer) 33
127.0.0.1:6379> Hget User2 Age
"33"
Hincrbyfloat  key field value action: is to increment the values of the field field in key by floating-point value

127.0.0.1:6379> Hincrbyfloat User2 Age 0.5
"33.5"

Hkeys key function: Returns all field in key
127.0.0.1:6379> Hkeys User2
1) "Name"
2) "Age"
3) "Height"
Kvals key function: Returns all the value in key
127.0.0.1:6379> hvals User2
1) "Wangwu"
2) "33"
3) "160"

Redis's hash operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.