Redis study notes (1)

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

  1. The data model is relatively simple
  2. Need more flexible application system
  3. Relatively high database performance requirements
  4. No need for high data consistency
  5. For a given key, it is easier to map to a complex value environment

Meet Redis

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.

Extension type

If there are too many requests, the server will be under pressure. It can be solved in the following two ways:

  1. 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.
  2. Horizontal expansion: Increase the number of servers. Can improve throughput.

Guarantee of high availability

Highly available system:

  1. Avoid single points of failure.
  2. Improve throughput (qps)
  3. Solutions after the amount of data increases

redis solution strategy

Master-slave mode: avoid single point of failure

Insert picture description here


Sentinel mode: The solution after increasing the amount of data.

Insert picture description here

Cluster mode: Improve throughput

Insert picture description here

Advantages of Redis

  1. high speed. The official claim: the speed of writing can reach 8w/s, and the speed of reading can reach 11w/s.
  2. Provide rich data types. String, List, Set, Zset, Hash
  3. 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.
  4. Rich features. Support publish/subscribe, notification, key expiration and other features.
  5. 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.
  6. Highly available distributed

Official website
document

Redis installation

Install Redis under Ubuntu

netstat -ntlp  查看当前端口占用情况
redis-server --port 端口  # 指定端口号

Common configuration

-- 配置后台启动 
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 向前找这个词