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