[Redis Chapter4] Hash

Source: Internet
Author: User

Hasehes

Redis Hash is a string-type field and value mapping table. Hash is particularly suitable for storing objects . Save as a string, you can now use less memory in a hash type. And it can be more convenient to store the entire object.


Hset

Redis 127.0.0.1:6379> hset user:001 name Michael

(integer) 1

Redis 127.0.0.1:6379> hget user:001 Name

"Michael"


Hsetnx

Redis 127.0.0.1:6379> hsetnx user:003 name Jason

(integer) 1

Redis 127.0.0.1:6379> hsetnx user:003 name Tom

(integer) 0-- set failed

Redis 127.0.0.1:6379> hget user:003 Name

"Jason" --value is not changed.


Hmset/hmget


Redis 127.0.0.1:6379> hmset user:004 name Michael age 1 Sex

Ok

Redis 127.0.0.1:6379> hget user:004 Name

"Michael"

Redis 127.0.0.1:6379> Hget user:004 Age

"29"

Redis 127.0.0.1:6379> hget user:004 Sex

"1"

Redis 127.0.0.1:6379> hmget user:004 name age sex

1) "Michael"

2) "29"

3) "1"


Hincrby

Redis 127.0.0.1:6379> Hincrby user:004 age 5

(integer) 34

Redis 127.0.0.1:6379> Hget user:004 Age

"34"


Hexists

Redis 127.0.0.1:6379> hexists user:004 Age

(integer) 1

Redis 127.0.0.1:6379> hexists user:004 Address

(integer) 0


Hlen

Redis 127.0.0.1:6379> Hlen user:004

(integer) 3


Hdel

Redis 127.0.0.1:6379> Hdel user:004 Age

(integer) 1

Redis 127.0.0.1:6379> hexists user:004 Address

(integer) 0

Redis 127.0.0.1:6379> Hget user:004 Age

(nil)


Hkeys hvals Hgetall

Redis 127.0.0.1:6379> Hkeys user:004

1) "Name"

2) "Sex"

Redis 127.0.0.1:6379> hvals user:004

1) "Michael"

2) "1"

Redis 127.0.0.1:6379> Hgetall user:004

1) "Name"

2) "Michael"

3) "Sex"

4) "1"




This article is from the "Software Design and Development" blog, please be sure to keep this source http://yuanzhitang.blog.51cto.com/2769219/1783356

[Redis Chapter4] Hash

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.