Article directory
1. Know Redis
REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo and is a cross-platform non-relational database. Saying this, you may not know Redis, MySQL must have been in contact with your friends in college. This is because some friends said that I have not been in contact with them in college. Maybe you have no impression of sleeping in college class, and other databases Oracle, SQL server should have known, so what is the difference between them?
Redis
It is an open source written in ANSI C language, complies with the BSD protocol, supports the network, can be based on memory, distributed, optional persistent key-value pair (Key-Value) storage database, and provides APIs in multiple languages.
MySQL
It is the most popular relational database management system, and MySQL is one of the best RDBMS (Relational Database Management System: relational database management system) application software in WEB application.
Oracle
It is a relational database management system from Oracle Corporation. It is a product that has been leading the way in the database field. It can be said that the Oracle database system is a popular relational database management system in the world. The system has good portability, convenient use and strong functions, and is suitable for all kinds of large, medium and small computer environments. It is an efficient, reliable, and high-throughput database solution.
and SQL server
homework to find out for yourself.
2. Relational and non-relational databases
What is the difference between relational and non-relational databases?
- Different data storage methods: relational databases are in tabular form, non-relational databases are in document or graph structure
- Different expansion methods: relational databases can be scaled vertically to improve processing capacity, non-relational databases are naturally distributed, and the load is shared through more data servers
- Transaction processing support is different: relational databases are good at handling fine-grained control of transaction atomicity, facilitating transaction rollback, while non-relational databases focus on processing big data. And generally does not guarantee compliance with ACID principles (ie atomicity, consistency, isolation, durability)
3. Advantages of Redis
- Extremely high performance - Redis can read at 110,000 times/s and write at 81,000 times/s.
- Rich data types – Redis supports Strings, Lists, Hashes, Sets and Ordered Sets data type operations for binary cases.
- Atomic – All operations in Redis are atomic, meaning that they either execute successfully or fail to execute at all. A single operation is atomic. Transactions are also supported for multiple operations, i.e. atomicity, wrapped by MULTI and EXEC instructions.
- Rich features – Redis also supports publish/subscribe, notifications, key expiration and more.
Fourth, the main use scenarios of Redis
We now know that Redis has extremely high concurrent read and write performance, so what are the usage scenarios of Redis database in actual development?
Let's briefly divide the usage scenarios of Redis according to its characteristics, and you will find that there are still many things that Redis can do.
1. High performance and high concurrency
- To do data caching, before querying the database, go to Redis to find the cache, which can reduce the time of querying the database.
- Spike system
2. Rich data formats
- Province and city table, dictionary table, map site
- Set collection that can be used to find mutual friends of two people
3. Single thread
- Distributed lock
4. Automatic expiration
- Do SMS verification code
- Product display with time limit
The above usage scenarios are just a few simple lists based on the characteristics of Redis. In the following articles, I will also introduce the specific use of Redis in some scenarios. Of course, the usage scenarios of Redis are definitely not limited to these, other It also needs to be used according to the actual application scenario!
Five, Redis installation
Download address: https://github.com/tporadowski/redis/releases
1. Click the link to download the second zip.
2. Select your installation path and the decompressed style.
3. Open the command line window, switch to the Redis directory, and enter the following command line.
redis-server.exe redis.windows.conf
4. Start the server, as shown in the following format, indicating that Redis is installed successfully
5. Do not close the above server, reopen the new server, switch to Redis, and enter the following command line.
redis-cli.exe -h 127.0.0.1 -p 6379
6. Basic command usage of Redis
1. Redis database switch, switch to No. 6 database, the following content No. 6 database as an example
SELECT 6
2. Enter and obtain data
The most basic commands in Redis to enter and get values are the SET and GET commands
For example, we set a key-value pair whose index is "mykey" and whose value is "zhangsan".
SET key value
typed successfully
3.GET to get the value of your key
GET key
Returns null if the value does not exist
GET key
4. Get all data: KEYS *, apparently I only create one index value in database No. 6.
KEYS *
5. Clear part of the data, that is, all the data in a database, that is, I will clear all the data in the No. 6 database first.
FLUSHDB
6. Clear all the data of the library, that is, delete the library and run away, the rice in the prison is really fragrant, so this command line is used carefully
FLUSHALL
7. Delete the key-value of the database
DEL key
8. Get the specified data type
Redis is often referred to as a data structure server because values can be of types such as String, Hash, list, sets, and sorted sets.
TYPE KEY
Well, the learning tasks in this issue are here. If there is anything wrong with the article, you can contact me and exchange it. Thank you for your three connections, and we will see you next time.