One, relational database and non-relational database
1. Relational database
Relational database is a structured database, created on the basis of a relational model (two-dimensional table model)
Generally record-oriented
Mainstream relational databases include Ocacle, MySQL, SQL Server, Microsoft, Access, DB2, etc.
SQL statement (standard data query language) is a language based on relational database, used to perform retrieval and operation of data in relational database
2. Non-relational database
NoSQL (NoSQL = Not Only SQL), which means "not just SQL", is a general term for non-relational databases
Except for mainstream relational databases, all databases are considered non-relational
The mainstream NoSQL databases include Redis, MongBD, Hbase, Memcached, etc.
3. Difference
3.1 Different data storage methods
The main difference between relational and non-relational databases is the way data is stored
Relational data is naturally in table format, so it is stored in the rows and columns of the data table
Data tables can be stored in association with each other, and it is easy to extract data
On the contrary, non-relational data is not suitable for storing in the rows and columns of the data table, but is grouped together in large chunks
Non-relational data is usually stored in data sets, like documents, key-value pairs, or graph structures
Your data and its characteristics are the primary factors influencing the choice of data storage and retrieval methods
3.2 Different expansion methods
The biggest difference between SQL and NoSQL databases may be in the way of expansion. To support the increasing demand, of course, it must be expanded.
To support more concurrency, the SQL database is scaled vertically, which means to increase processing power and use faster computers, so that the same data set can be processed faster
Because the data is stored in relational tables, the performance bottleneck of the operation may involve many tables, all of which need to be serviced by improving computer performance. Although the SQL database has a lot of room for expansion, it will definitely reach the upper limit of vertical expansion in the end
The NoSQL database is scaled horizontally
Because non-relational data storage is naturally distributed, the expansion of NoSQL databases can share the load by adding more ordinary database servers (nodes) to the resource pool
3.3 Different support for transactional
If data operations require high transactionality or complex data queries need to control the execution plan, then traditional SQL databases are your best choice in terms of performance and stability
SQL database supports fine-grained control of transaction atomicity, and it is easy to roll back transactions
Although NoSQL databases can also use transaction operations, they cannot be compared with relational databases in terms of stability, so their real shining value lies in the scalability of operations and the processing of large amounts of data.
4. The background of non-relational data
Both relational databases and non-relational databases have their own characteristics and application scenarios. The close combination of the two will bring new ideas to the development of Web2.0 databases
Relational databases focus on relations, non-relational databases focus on storage
For example, in a MySQL database environment where read and write are separated, frequently accessed data can be stored in a non-relational database to improve access speed
Demand-driven development:
Demand for high concurrent reading and writing of the database
Demand for efficient storage and access to massive data
Demand for high scalability and high availability of the database
5. Summary
Relational Database:
Example -> database -> table (table) -> record row ((row), data field (column)
Non-relational database:
Example -> database -> collection -> key-value pair (key-value)
Non-relational databases do not need to manually build databases and collections (tables)
2. Introduction to Redis
1. Overview of Redis
Redis is an open source NoSQL database written in C language
Redis runs on memory and supports persistence. It uses a key-value (key-value pair) storage form, which is an indispensable part of the current distributed architecture.
The Redis server program is a single process model, that is to say, multiple Redis processes can be started at the same time on a server, but the actual processing speed of Redis is completely dependent on the execution efficiency of the main process
If only one Redis process is running on the server, but there are multiple clients accessing at the same time, the processing capacity of the server will be reduced to a certain extent
If multiple Redis processes are started on the same server, Redis will increase the concurrent processing capability and also put a lot of pressure on the server's CPU.
Summary: In an actual production environment, you need to decide how many Redis processes to start based on actual needs. If you have higher requirements for high concurrency, you may consider starting multiple processes on the same server, and if the CPU resources are relatively tight, Just use a single process
2. Advantages of Redis
It has a very high data read and write speed: the data read speed can reach up to 110,000 times/s, and the data write speed can reach up to 81,000 times/s
Support rich data types: support key-value, Strings, Lists, Hashes, Sets and Ordered Sets and other data type operations
Support data persistence: the data in the memory can be saved in the disk, and it can be loaded again for use when restarting
Atomicity: All Redis operations are atomic
Support data backup: data backup in master-salve mode
Redis is a memory-based database, and cache is one of its most commonly used fields. In addition, the common application scenarios of Redis also include the operation of obtaining the latest N data, ranking applications, counter applications, storage relationships, and real-time Analysis system, log record