Redis03 using Redis Database (hashes type)

Source: Internet
Author: User

Type and operation of a hashes

Redis Hash is a string-type field and value mapping table. It's added, the delete operation is 0 (1) (average). Hash is particularly suitable for storing objects, compared to Gencun each word of an object into a single string type. Storing an object in a hash type consumes less memory and makes it easier to access the entire object.

1 Hset

Sets the hash field to the specified value, and if key does not exist, it is created first.

Redis 127.0.0.1:6379> hset user:001 name Lisi
(integer) 0
Redis 127.0.0.1:6379> hget user:001 Name
"Lisi"

2.hsetnx

Sets the hash field to the specified value, and if key does not exist, it is created first. Returns 0 if present.

127.0. 0.1:6379> Hsetnx User:0010127.0. 0.1:6379> Hget User:001  name"Lisi"

3,hmset

Multiple field with hash set

Redis127.0.0.1:6379>hmset myhash field1 Hello field2 worldokredis127.0.0.1:6379>hget myhash field1"Hello"Redis127.0.0.1:6379>hget Myhash field2" World"Redis127.0.0.1:6379>

4 Hget

Gets the specified hash field

5. Hmget

Gets all the specified hash field

Redis127.0.0.1:6379>hmset myhash field1 Hello field2 worldokredis127.0.0.1:6379>hget myhash field1"Hello"Redis127.0.0.1:6379>hget Myhash field2" World"Redis127.0.0.1:6379>hmget myhash field1 field21)"Hello"2)" World"

6. Hincrby

Specifies the hash field plus the given value.

Redis127.0.0.1:6379> Hset Myhash Age1(integer)1Redis127.0.0.1:6379>hget Myhash Age"1"Redis127.0.0.1:6379> Hincrby Myhash Age8(integer)9Redis127.0.0.1:6379>hget Myhash Age"9"

7. hexists

Tests whether the specified field exists.

127.0. 0.1:6379>1

8 Hlen

Returns the number of field for the specified hash

127.0. 0.1:6379>3

9. Hdel

Delete field with specified hash

127.0. 0.1:6379>1

Ten. Hkeys

Return hash of all field

127.0. 0.1:6379> hkeys myhash1"field2"2"  Age"

Hgetall.

Gets all the field and value in a hash.

127.0. 0.1:6379> hgetall myhash1"field2"2 "  World " 3 "  Age " 4 " 9 "

Redis03 using Redis Database (hashes type)

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.