In the previous articles, we introduced the basic data types and usage methods of redis. This article will introduce some database management commands.
1. How to Select a database
// Redis contains databases represented by numbers 0-15. Database 0 is selected by default. Syntax: select [Database Number] // Database Number: 0-15 // If the selection is successful, Return OK. Otherwise, the system prompts that your database index number is invalid.
2. view the total number of keys in the current database
Syntax: dbsize // The command is relatively simple
3. Obtain the settings of the redis. conf configuration file.
Syntax: config get [pattern] // pattern: similar to a regular expression; "*": any length character; Example 1: Get all redis. CONF configuration information config get * Example 2: Get redis. CONF configuration dir attribute information config Get dir Example 3: Get configuration information starting with D config get D *
4. Obtain redis-related information
Syntax: info // including information such as redis version and System
5. Determine whether to connect to the redis Server
Syntax: Ping // If the connection is normal, Pong is returned. Otherwise, the connection fails.
6. Clean up the database
Syntax 1: flushdb // clear the current database syntax 2: flushall // clear all databases 0-15
7. log out
Syntax 1: Quit syntax 2: Exit syntax 3: Ctrl + c
8. view the key list in the current database
Syntax: Keys [pattern] // pattern: expression example: Keys * // obtain the list of all keys in the current database. Keys LIST _ * // obtain the list of keys starting with LIST _ in the current database.
9. delete a specified key
Syntax: del [key name] example: del name // delete a key named name. If the key is successfully deleted, 1 is returned. Otherwise, 0 is returned.
10. Determine whether the key exists
Syntax: exists [key name] example: exists name // determines whether the key with the name exists. If yes, 1 is returned; otherwise, 0 is returned.
11. Set the key expiration time
Syntax: expire [key name] [expiration time (unit: seconds)] // effect similar to setex example: expire name 10 // set the name expiration time to 10 seconds, it can be the same as the TTL command to view the name's validity period. For example, TTL name, "-1" indicates that it has expired; otherwise, the current validity period is returned.
12. Move the key to the specified database
Syntax: Move [key name] [Database Number] example: Move name 1 // move name from current database to database 1
13. Persistence key
Syntax: persist [key name] // when expire is used, it has not expired. If you want to cancel the expiration setting, you can run the // command to cancel the expiration time and persistence operation. Example: persist name
14. Rename the key
Syntax: RENAME [old key] [new key] example: Rename name name1 // rename name to name1
15. view the data type of the key
Syntax: Type [key name] // return the Data Type of the key
This article from the "Java program" blog, please be sure to keep this source http://793404905.blog.51cto.com/6179428/1550061
[Redis management] basic commands