[Redis data structure] hash type

Source: Internet
Author: User

Before explaining the syntax knowledge, we will teach you how to master the basic Hidden Rules of hash. in different languages, it is called hash and map, hash can be considered as a set of key-value pairs. I first add the map concept in Java to the redis hash without authorization, so that we can better understand the hash rules:

I. Hash rules

1. ing model

Value set ing, key set ing, and entry set ing (key-value, which must be called item (Python )).

2. General Method list

Add, delete, update, and determine whether a key exists, key set, value set, and entry set corresponding to the ing model;

In other languages, the above method type list is also basically included.


Ii. Hash syntax and usage in redis

1. How to add a hash table entry

# Add an element to the specified hash table. If the hash table does not exist, create the hash table. Syntax: hset [hash table name] [Key] [value] # create a user1 hash table and add the Entry Example of key = Name, value = 51cto: hset user1 name 51cto

2. How to obtain hash table element data

# Obtain the value corresponding to the key of the specified hash table. If no nil syntax is returned: hget [hash table name] [Key] # Return 51cto example: hget user1 name

3. How to delete Hash Table Elements

# Delete the entry syntax of the specified hash table: hdel [hash table name] [key1] [key2]... [keyn] # delete the name Entry Example in user1: hdel user1 name

4. How to determine whether a hash table element exists

# Determine whether the object syntax of the specified key exists in the hash table: hexists [hash table name] [Key] # If the name exists, 1 is returned; otherwise, 0 is returned. Example: hexists user1 name

5. How to obtain the hash table size

# Syntax for getting the length (size) of a specified hash table: hlen [hash table name] # example for getting the length of a hash table in user1: hlen user1

6. Hash Table ing model

# Value ing model: syntax for getting all hash values: hvals [hash table name] # key ing model: syntax for getting all hash keys: hkeys [hash table name] # object ing model: Get all hash object set Syntax: hgetall [hash table name]

7. other auxiliary tools

# Auto-increment Syntax: hincrby [hash table name] [Key] [step size] # auto-increment the value of age in user1. Example 1: hincrby user1 age 1

Note: This article only describes the hash syntax related to redis.



This article from the "Java program" blog, please be sure to keep this source http://793404905.blog.51cto.com/6179428/1548164

[Redis data structure] hash 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.