定义理解
缓存分类
缓存原理
Web项目常见的缓存场景

缓存的操作流程


Redis简介
Redis支持的语言

Redis支持的数据类型
yum -y install gcc-c++ autoconf automake

tar zxvf redis-5.0.3.tar.gz
切换到解压目录
编译源代码
创建redis的安装目录
如果需要指定安装路径,需要添加PREFIX参数**
服务端启动
前台启动
./redis-server
后台启动
## 创建一个配置文件目录
mkdir -p /opt/yjx/redis/conf
## 拷贝配置文件到目录中
cp ~/redis-5.0.3/redis.conf /opt/yjx/redis/conf

后台启动
./redis-server /opt/yjx/redis/conf/redis.conf
总结
前台启动
./redis-server
后台启动
./redis-server /opt/yjx/redis/conf/redis.conf
客户端启动
要在指定的目录下启动客户端(配置后的命令)
[root@basenode ~]# cd /opt/yjx/redis/bin/
[root@basenode bin]# ./redis-cli -a 123456






定义理解
理解
特点
RDB的三种触发机制
save触发方式

bgsave触发模式

自动触发
#配置文件
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
save 900 1
save 300 10
save 60 10000
#配置文件的意义
服务器在 900 秒之内,对数据库进行了至少 1 次修改,就对操作保存
服务器在 300 秒之内,对数据库进行了至少 10 次修改,就对操作保存
服务器在 60 秒之内,对数据库进行了至少 10000 次修改,就对操作保存
# However if you have setup your proper monitoring of the Redis
server
# and persistence, you may want to disable this feature so that
Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
# 默认值为yes。当启用了RDB且最后一次后台保存数据失败,Redis是否停止接收数据。
stop-writes-on-bgsave-error yes
# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no'
but
# the dataset will likely be bigger if you have compressible values
or keys.
# 默认值是yes。对于存储到磁盘中的快照,可以设置是否进行压缩存储。
rdbcompression yes
# RDB files created with checksum disabled have a checksum of zero
that will
# tell the loading code to skip the check.
# 默认值是yes。在存储快照后,我们还可以让redis使用CRC64算法来进行数据校验,但是
这样做会增加大约10%的性能消耗
rdbchecksum yes
# The filename where to dump the DB
# 设置快照的文件名,默认是 dump.rdb
dbfilename dump.rdb
# The working directory.
# The DB will be written inside this directory, with the filename
specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
# 设置快照文件的存放路径,这个配置项一定是个目录,而不能是文件名
dir ./
RDB的优势和劣势
对于RDB的劣势的改进

Rwrite策略
对AOF文件重写(Rwrite)的深入理解

AOF配置信息
############################## APPEND ONLY MODE ###############################
# By default Redis asynchronously dumps the dataset on disk. This mode
is
# good enough in many applications, but an issue with the Redis process
or
# a power outage may result into a few minutes of writes lost (depending
on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsyncpolicy
AOF的触发策略
AOF优势和劣势
成年人不做选择题
如果同时使用AOF和RDB,那么启动时以AOF为恢复数据的模板
选择的话,两者加一起才更好。
因为两个持久化机制你明白了,剩下的就是看自己的需求了,需求不同选择的也不一定,但是通常都是结合使用
两者的比较

主从集群的产生背景
Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况。为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构,
Redis主从复制可以根据是否是全量分为全量同步和增量同步

在Redis主配置文件文件夹中创建配置文件
主节点配置文件
## 导入一个通用配置文件
include /opt/yjx/redis/conf/redis.conf
## 当前主服务器端口
port 7100
## 设置主服务密码
requirepass 123456
## 当前主服务进程ID
pidfile /var/run/redis_7100.pid
## 当前主服务RDB文件名称
dbfilename dump7100.rdb
## 当前主服务文件存放路径
dir /opt/yjx/redis/conf/
从节点需要配置
## 导入一个通用配置文件
include /opt/yjx/redis/conf/redis.conf
## 当前主服务器端口
port 7100
## 当前主服务进程ID
pidfile /var/run/redis_7200.pid
## 当前主服务RDB文件名称
dbfilename dump7200.rdb
## 当前主服务文件存放路径
dir /opt/yjx/redis/conf/
## 同步master节点的网络信息(低版本必须使用slaveof,高版本推荐使用replicaof)
replicaof 192.168.88.101 7100
## 设置master节点的密码信息
masterauth 123456
## 从节点只做读的操作,保证主从数据的一致性
slave-read-only yes
结束从服务器的命运(结束)
理解
全量同步
同步时机
同步步骤

增量同步
同步时机
同步过程
主从复制的异步特性
断线重连
重连过程

监控(monitoring):
提醒(Notifation):
自动故障转移(Automatic failover):
当哨兵发现其中的节点宕机后,如果这个节点是,会自动选举备用节点成为新的主节点
当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会将失效主服务器的其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器;
当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。
