Classification of the database
Relational and non-relational databases
Relational databases. Relational databases include Oracle, MySQL, SqlServer, and DB2.
Non-relational (NoSQL) databases:
What problem to solve: NoSQL data is created to solve the challenges brought by large-scale data collections and multiple data types, especially Big data application problems.
Classification of non-relational databases
Store database based on key-value: This type of database mainly uses a hash table in which a specific key and pointer point to specific data.
Column storage database: This part of the database is usually used to deal with distributed storage of massive data, the key still exists, but their characteristic is to point to multiple columns. These columns are arranged by column families. Such as HBASE, Riak.
Characteristics of non-relational data
- The data model is relatively simple
- Need more flexible application system
- Relatively high database performance requirements
- No need for high data consistency
- For a given key, it is easier to map to a complex value environment
What is Redis
redis is a simple, efficient, distributed, based memory cache non-relational databases. After setting up the server, connect through the network to provide key-value service. Simplicity is the outstanding feature of Redis. Simplicity can ensure the stability and excellence of core functions.
If there are too many requests, the server will be under pressure. It can be solved in the following two ways:
- Vertical expansion: Increase resources, and replace components with better performance on which components are under high pressure. Such as replacing the CPU. But IO has a bottleneck. Limited by the system, it can't be upgraded to a certain level.
- Horizontal expansion: Increase the number of servers. Can improve throughput.
Guarantee of high availability
Highly available system:
- Avoid single points of failure.
- Improve throughput (qps)
- Solutions after the amount of data increases
redis solution strategy
Master-slave mode: avoid single point of failure
Sentinel mode: The solution after increasing the amount of data.
Cluster mode: Improve throughput
Advantages of Redis
- high speed. The official claim: the speed of writing can reach 8w/s, and the speed of reading can reach 11w/s.
- Provide rich data types. String, List, Set, Zset, Hash
- Atomic operation. A single operation is atomic, and multiple operations also support transactions, that is, atomicity. Multiple commands can be executed simultaneously through the MULTI and EXEC instructions, but there is no guarantee that they will succeed and fail together.
- Rich features. Support publish/subscribe, notification, key expiration and other features.
- Persistence mechanism. Redis is a tool based on memory caching, which means that once the machine breaks the data will be lost, but it provides operations that are persisted to the hard disk.
- Highly available distributed
netstat -ntlp 查看当前端口占用情况 redis-server --port 端口 # 指定端口号
-- 配置后台启动 daemonize yes -- 配置远程登录 绑定端口 bind 0.0.0.0 配置工作目录 dir /var/lib/redis/data 配置日志文件 日志文件默认会回收到回收站，指定后就在工作目录下且文件名为redis_6379.log log var/lib/redis/"6379.log" 关闭客户端： redis-cli -h 127.0.0.1 -p 6379 shutdown redis-cli shutdown redis-server: /usr/bin/redis-server redis: /etc/redis / n 就分别是向后找 N 向前找这个词