Redis简记
安装
1 | # 下载 |
如果没安装make
1 | sudo apt-get install make |
如果没安装gcc
1 | sudo apt-get install gcc |
如果报错:jemalloc/jemalloc.h: No such file or directory
1 | make MALLOC=libc |
启动
1 | redis-server redis.conf & |
停止
1 | redis-cli -a 123456 shutdown |
集群(小哨兵)
master
配置主库
1 | # vi redis.conf |
启动主库
1 | redis-server redis.conf & |
sentinel
配置哨兵
1 | # vi sentinel.conf |
参数2表示:只要sentinel集群中有2个认为master无法连接之后,就会进行主从切换。
启动哨兵
1 | redis-sentinel sentinel.conf & |
slave
配置从库
1 | # vi redis.conf |
启动从库1
2
3
4
5redis-server redis.conf &
# 登录
redis-cli -a 123456
# 查看信息
INFO
sentinel
配置哨兵
1 | # vi sentinel.conf |
启动哨兵
1 | redis-sentinel sentinel.conf & |
测试
如果想弄清楚小哨兵的工作模式,必须亲手测试,比如杀死主库等。
SpringBoot
配置
1.application.yml1
2
3
4
5
6
7
8spring:
redis:
host: localhost
port: 6379
password: 123456
sentinel:
master: mymaster
nodes: localhost:26379
2.RedisConfigurer.java
1 | package com.kangyonggan.demo.configuration; |