Small ants Learn Redis notes (4) hashes type of--redis data type

Source: Internet
Author: User
Tags learn php

Hashes type

Hash is a string-type field and value mapping table. It is particularly well-suited for storing objects. Rather than 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.


Hashes Common Commands

1. Hset setting the fields and values of an object

Format: Hset user:001 name "Allen"

Meaning: For user:001 This object, set its name key to a value of Allen.

Note: If the same object is set multiple times with the same key, the last value will be overwritten. Returns 1 when the first setting succeeds, and the repeating setting returns 0.

2. Hsetnx Ibid, but the object's key cannot be duplicated

Format: hsetnx user:001 name "Amy"

Meaning: For user:001 This object, set its name key to a value of Amy, but this value exists, cannot be set, returns 0. If it does not exist, it is created. It's like the setnx.

3. Hmset bulk Set the key value of the object

Format: Hmset user:002 name "Allen" Age "sex" 1 "

Meaning: Bulk sets the key value of the object. Successful return OK. Overwrite occurs when repeating settings.

4. Hget gets the value of a key in the object

Format: Hget user:002 name

Meaning: Gets the value of the User:002 object key as name. If the key does not exist return null (nil)

5. Hmget bulk Get the value of an object

Format: hmget user:002 name age sex object followed by key to be viewed

Meaning: Returns the required value according to the order in which key is set, or null if the key does not exist (nil)

6. Hincrby increments the value of an element in an object by a specified number.

Format: Hincrby user:002 age 3

Meaning: For the age key in user:002, increment by 3 each time.

Note: This command, like Incrby, has a positive number increment and a negative number is decremented.

7. hexists Check if a field exists in the hash

Format: hexists user:002 name

Meaning: See if the name key exists in the user:002. There is a return of 1, and no return 0 exists.

8. Hlen view the number of keys in an object

Format: Hlen user:002

Meaning: See the number of keys in user:002.

9. Hdel Delete the key in the specified hash

Format: Hdel user:002 name

Meaning: Remove the name key of the object user:002. Delete succeeded, return 1. Failed to return 0.

Hkeys returns all keys for an object

Format: Hkeys user:002

Meaning: Returns all keys of user:002.

Hvals returns all the values of an object

Format: Hvals user:002

Meaning: Returns all values in the object user:002.

Hgetall returns all the contents of an object. There are keys, there are values.

Format: Hgetall user:002

Meaning: Returns all the contents of the User:002 object.

Note: If the object does not exist, return (empty list or set)


learn PHP's small ant original blog http://my.oschina.net/woshixiaomayi/blog




Small ants Learn Redis notes (4) hashes type of--redis data 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.