C:\Users\Administrator>cd C:\redis
redis-server.exe redis.windows.conf
redis-cli.exe -h 127.0.0.1 -p 6379
https://github.com/go-redis/redis
[root@kolla ~]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[root@kolla ~]# tar -zxvf redis-3.2.8.tar.gz
[root@kolla ~]# mv redis-3.2.8 /usr/local/redis/
[root@kolla ~]# cd /usr/local/redis/
[root@kolla redis]# yum install gcc make -y
[root@kolla redis]# make
安装tcl
[root@kolla redis]# cd
[root@kolla ~]# wget https://jaist.dl.sourceforge.net/project/tcl/Tcl/8.6.1/tcl8.6.1-src.tar.gz
[root@kolla ~]# tar -zxvf tcl8.6.1-src.tar.gz -C /usr/local/
[root@kolla ~]# cd /usr/local/tcl8.6.1/unix/
[root@kolla unix]# ./configure
[root@kolla unix]# make
[root@kolla unix]# make install
[root@kolla unix]# cd /usr/local/redis/
[root@kolla redis]# make test
[root@kolla redis]# make install
[root@kolla redis]# cd /usr/local/bin/
[root@kolla bin]# ls
redis-benchmark redis-check-rdb redis-sentinel tclsh8.6
redis-check-aof redis-cli redis-server
其中
redis-server redis服务器
redis-cli redis命令行客户端
redis-benchmark redis性能测试工具
redis-check-aof AOF文件修复工具
redis-check-rdb RDB文件检索工具
[root@kolla ~]# mkdir -p /etc/redis
[root@kolla ~]# cp /usr/local/redis/redis.conf /etc/redis/
修改配置文件
[root@kolla ~]# vi /etc/redis/redis.conf
61 #bind 127.0.0.1 //绑定IP:如果需要远程访问,可将此行注释,或绑定一个真实IP
84 port 6379
128 daemonize yes
是否以守护进程运行
a) 如果以守护进程运行, 则不会再命令行阻塞,类似于服务
b) 如果以非守护进程运行, 则当前终端被阻塞
c) 设置为yes表示守护进程, 设置为no表示非守护进程
d) 推荐设置为yes
数据文件
237 dbfilename dump.rdb //做持久化存储,关机的时候内存写入到硬盘,开机硬盘到内存
数据文件存储路径
247 dir /var/lib/redis
日志文件
163 logfile "/var/log/redis/redis-server.log"
数据库,默认有16个 0-15
178 databases 16
主从赋值,类似于双机备份(目前不变动)
265 # slaveof <masterip> <masterport>
-------------------------------------
启动服务端和客户端
(1)服务器端开启的命令为redis-server
[root@kolla ~]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
[root@kolla ~]#
(2)启动redis服务器端
[root@kolla ~]# ps aux | grep redis
root 2139 0.0 0.0 136980 7952 ? Sl 10:27 0:01 redis-server *:6379
root 2704 0.0 0.0 112716 964 pts/0 S+ 11:02 0:00 grep --color=auto redis
[root@kolla ~]#
[root@kolla ~]# mkdir -p /var/log/redis/
[root@kolla ~]# touch /var/log/redis/redis-server.log
[root@kolla ~]# redis-server /etc/redis/redis.conf
目前,按照这个命令启动
[root@kolla ~]# nohup redis-server &
(3)启动客户端
[root@kolla ~]# redis-cli
#总共16个数据库,0开始,下面代表0号数据库
127.0.0.1:6379>
#下面代表第十号数据库
127.0.0.1:6379> select 10
OK
127.0.0.1:6379[10]>
127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379> set name1 itcast
OK
127.0.0.1:6379> keys *
1) "name"
2) "name1"
127.0.0.1:6379> get name1
"itcast"
设置过期时间
127.0.0.1:6379> setex b1 3 itaima
OK
127.0.0.1:6379> get b1
"itaima"
127.0.0.1:6379> get b1
(nil)
一次性设置多个值
127.0.0.1:6379> mset a1 go a2 c a3 c++ a4 python
中文乱码
127.0.0.1:6379> append a1 "很棒"
(integer) 8
127.0.0.1:6379> get a1
"go\xe5\xbe\x88\xe6\xa3\x92"
127.0.0.1:6379> exit
[root@kolla ~]# redis-cli --raw
127.0.0.1:6379> get a1
go很棒
127.0.0.1:6379>
获取多个数值
127.0.0.1:6379> mget a1 a2
go很棒
c
查找,支持正则表达式
127.0.0.1:6379> keys a*
127.0.0.1:6379> EXISTS a1
1
127.0.0.1:6379> exists a1
1
127.0.0.1:6379>
查看键对应的value类型
127.0.0.1:6379> TYPE a1
string
127.0.0.1:6379>
删除键以及对应的值
127.0.0.1:6379> del a4
1
127.0.0.1:6379> exists a4
0
127.0.0.1:6379>
删除所有键
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
127.0.0.1:6379>
127.0.0.1:6379> mset a1 go a2 c a3 c++
OK
127.0.0.1:6379> mget a1 a2 a3
go
c
c++
127.0.0.1:6379>
127.0.0.1:6379> del a2 a3
2
127.0.0.1:6379> keys *
a1
127.0.0.1:6379>
重新设置过期时间
127.0.0.1:6379> SETEX name 100 itcast
OK
127.0.0.1:6379> expire name 10
1
127.0.0.1:6379> get name
itcast
127.0.0.1:6379> get name
127.0.0.1:6379>
127.0.0.1:6379> hdel haha name
删除
irem key count value
。删除指定元素
。讲列表中前count次出现的值为value的元素移除
。count > 0 从头往尾移除
。count < 0 从尾往头移除
127.0.0.1:6379> rpush a3 a b a b a b
6
127.0.0.1:6379> lrange a3 0 -1
a
b
a
b
a
b
127.0.0.1:6379>
127.0.0.1:6379> zrange a5 0 -1
list
wangwu
zhaoliu
127.0.0.1:6379> zrem a5 list wangwu
2
127.0.0.1:6379> zrange a5 0 -1
zhaoliu
127.0.0.1:6379>
根据权重删除
127.0.0.1:6379> ZREMRANGEBYSCORE a5 4 5
2
127.0.0.1:6379> zrange a5 0 -1
zhangsan
zhaoliu
127.0.0.1:6379>