安装redis的方式
-yum (删除这个yum安装的redis,咱们只用源码编译安装的)
-rpm
-源码编译html
删除本来的redis
yum remove redis -ylinux
解压缩
tar -zxf redis-4.0.10.tar.gzredis
切换redis源码目录
cd redis-4.0.10数据库
默认在/usr/local/bin缓存
指定redis的配置文件 启动 redis
redis-6666.conf 内容以下app
port 6666 #redis端口 daemonize yes #后台运行redis pidfile /data/6666/redis.pid # pid号码 loglevel notice #日志等级 logfile "/data/6666/redis.log" #日志文件存放路径 dir /data/6666 #redis数据目录 requirepass haohaio #redis的密码
指定配置文件启动redis服务端
redis-server redis-6666.confide
检查redis的进程,端口
ps -ef |grep redis
netstat -tunlp |grep redis学习
登陆redis数据库
redis-cli -p 6666
登陆后 输入密码才可访问
auth haohaioui
rdb持久化还有时间策略
save 900 1 # 秒 1个修改类的操做
save 300 10 # 秒 10个操做
save 60 10000 # 秒 10000个操做日志
使用rdb持久化的方式,在配置文件中,打开rdb持久化
cat redis-6666.conf
内容以下
port 6666 daemonize yes pidfile /data/6666/redis.pid loglevel notice logfile "/data/6666/redis.log" dir /data/6666 dbfilename redis.dump
关闭redis服务端,准备重启
redis-cli -p 6666 -a haohaio shutdown
使用新的支持rdb持久化的配置文件启动
redis-server redis-6666.conf
手动触发rdb持久化
经过save指令
让配置文件支持按期持久化
port 6666 daemonize yes pidfile /data/6666/redis.pid loglevel notice logfile "/data/6666/redis.log" dir /data/6666 dbfilename redis.dump save 900 1 #rdb机制 每900秒 有1个修改记录 save 300 10 #每300秒 10个修改记录 save 60 10000 ~
配置redis支持aof持久化
cat redis-6666.conf
内容以下
port 6666 daemonize yes pidfile /data/6666/redis.pid loglevel notice logfile "/data/6666/redis.log" dir /data/6666 appendonly yes appendfsync everysec
指定配置文件启动,支持aof
redis-server redis-6666.conf 在第一次启动的时候,就开启了aof持久化
不重启redis,切换rdb数据到aof数据中
准备一个rdb的redis数据库
port 6666 daemonize yes pidfile /data/6666/redis.pid loglevel notice logfile "/data/6666/redis.log" dir /data/6666 dbfilename redis.dump save 900 1 save 300 10 save 60 10000
启动redis支持rdb的数据库
设置redis的数据,手动save触发持久化,生成持久化数据文件
经过命令,切换持久化模式
127.0.0.1:6379> CONFIG set appendonly yes #开启AOF功能
OK
127.0.0.1:6379> CONFIG SET save "" #关闭RDB功能
OK
修改redis的配置文件,改成aof,便于之后重启,彻底切换到aof模式
redis-6666.conf内容以下
port 6666 daemonize yes pidfile /data/6666/redis.pid loglevel notice logfile "/data/6666/redis.log" dir /data/6666 appendonly yes appendfsync everysec
实验完毕
redis-server redis.conf
PUBLISH channel msg
将信息 message 发送到指定的频道 channel
SUBSCRIBE channel [channel ...]
订阅频道,能够同时订阅多个频道
UNSUBSCRIBE [channel ...]
取消订阅指定的频道, 若是不指定频道,则会取消订阅全部频道
PSUBSCRIBE pattern [pattern ...]
订阅一个或多个符合给定模式的频道,每一个模式以 * 做为匹配符,好比 it* 匹配所 有以 it 开头的频道( it.news 、 it.blog 、 it.tweets 等等), news.* 匹配全部 以 news. 开头的频道( news.it 、 news.global.today 等等),诸如此类
注意:使用发布订阅模式实现的消息队列,当有客户端订阅channel后只能收到后续发布到该频道的消息,以前发送的不会缓存,必须Provider和Consumer同时在线。
博客地址:
http://www.javashuo.com/article/p-ufazueso-co.html 博客汇总
http://www.javashuo.com/article/p-cglbaabl-eh.html redis