Redis学习笔记


1 安装流程

cd redisxxxx

make MALLOC=libc

make test

cd src
make install
cd ..
mkdir etc
mkdir bin
cp redis.conf etc/
cp mkreleasehdr.sh redis-check-aof redis-check-rdb redis-cli redis-server ../bin
cd ../bin
./redis-server

2 查找安装位置方法

3 后台启动方法

 redis.conf 设置 deamon yes

然后指定配置文件启动

./redis-server ../etc/redis.conf

 4 redis 关闭方法

./redis-5.0.5/bin/redis-cli shutdown

5 注意

用cli需指定端口,否则默认连接6380
logfile配置相对路径默认为当前的敲命令的路径

6 查看 master /slave状态

info replication

配置redis有三种 ,单节点,主从,哨兵(主从的修改版本,可以进行slave的选举),最后是集群

 7 搭建集群需要修改的配置

cp redis-trib.rb /usr/local/bin/

port 7000 //端口7000,7002,7003
bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置
appendonly yes

/root/soft/redis/cluster/redis-5.0.57001/src/redis-server /root/soft/redis/cluster/redis-5.0.57001/redis.conf

/root/soft/redis/cluster/redis-5.0.57001/src/redis-server /root/soft/redis/cluster/redis-5.0.57001/redis.conf
/root/soft/redis/cluster/redis-5.0.57002/src/redis-server /root/soft/redis/cluster/redis-5.0.57002/redis.conf
/root/soft/redis/cluster/redis-5.0.57003/src/redis-server /root/soft/redis/cluster/redis-5.0.57003/redis.conf
/root/soft/redis/cluster/redis-5.0.57004/src/redis-server /root/soft/redis/cluster/redis-5.0.57004/redis.conf
/root/soft/redis/cluster/redis-5.0.57005/src/redis-server /root/soft/redis/cluster/redis-5.0.57005/redis.conf


redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

yum -y install ruby ruby-devel rubygems rpm-build
gem install redis

redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
set sss sss
keys *


ruby -v 查看版本低于2.3,需要升级

gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

curl -sSL https://get.rvm.io | bash -s stable

 4、查找配置文件 find / -name rvm.sh 
 5、配置文件生效 source /etc/profile.d/rvm.sh 
 6、下载rvm依赖 rvm requirements 
 7、查看rvm库ruby版本 rvm list known
 8、安装ruby指定版本 rvm install ruby-2.4.1
 9、使用ruby版本默认 rvm use 2.4.1 default

3 Redis 事务

命令的方式

multi

set/get

exec

如果 中断使用 discard

multi

set

discard

exec,会不执行exec

如果集成spring 参考 SessionCallback 参考网上

4 redis备份

备份采用  快照, 卡,但是恢复的时候快

aof 追加方式,虽然快,但是回复起来慢,默认应该都是aof??

appendonly no 用快照

yes 表示用aof

原文地址:https://www.cnblogs.com/genestart/p/11166882.html