1.环境准备
[root@CO7 ~]# yum install gcc-c++
2.解压安装redis
[root@CO7 ~]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz
[root@CO7 ~]# ls
redis-4.0.10.tar.gz
[root@CO7 ~]# tar zxvf redis-4.0.10.tar.gz
[root@CO7 ~]# cd redis-4.0.10/
[root@CO7 redis-4.0.10]# make
[root@CO7 redis-4.0.10]# cd src
[root@CO7 src]#make test
[root@CO7 src]#yum -y install tcl #(或者下载上传http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
)
[root@CO7 src]#make test
[root@localhost src]# make PREFIX=/usr/local/redis install
bin目录中都是工具命令
3.把解压的redis路径下的redis.conf文件拷贝到安装路径下面
[root@CO7 bin]# cd /root/redis-4.0.10
redis-4.0.10/ redis-4.0.10.tar.gz
[root@CO7 bin]# cd /root/redis-4.0.10/
[root@CO7 redis-4.0.10]# ls
00-RELEASENOTES CONTRIBUTING deps Makefile README.md runtest runtest-sentinel src utils
BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests
[root@CO7 redis-4.0.10]# cp redis.conf /usr/local/redis/
[root@CO7 redis-4.0.10]# cd /usr/local/redis/
[root@CO7 redis]# ls
bin redis.conf
4.启动redis
<1>方法一&#xff1a;
[root&#64;CO7 redis]# cd bin/
[root&#64;CO7 bin]# ./redis-server
显示已经启动成功了&#xff0c;但是这属于前端启动&#xff0c;启动redis之后&#xff0c;我们的控制台就不能进行任何操作了&#xff0c;只能ctrl&#43;c停止启动。
<2>方法二&#xff1a;&#xff08;后端启动&#xff09;
[root&#64;CO7 redis]# vim redis.conf
找到daemonize no将其改为yes
[root&#64;CO7 redis]# ls
bin redis.conf
[root&#64;CO7 redis]# ./bin/redis-server ./redis.conf
19321:C 15 Sep 06:08:59.496 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19321:C 15 Sep 06:08:59.496 # Redis version&#61;4.0.10, bits&#61;64, commit&#61;00000000, modified&#61;0, pid&#61;19321, just started
19321:C 15 Sep 06:08:59.496 # Configuration loaded
[root&#64;CO7 redis]# ps -ef | grep -i redis
root 19322 1 0 06:08 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379
root 19327 11527 0 06:09 pts/2 00:00:00 grep --color&#61;auto -i redis
5.关闭redis
[root&#64;CO7 redis]# ./bin/redis-cli shutdown
使用操作&#xff1a;
//首先链接客户端
[root&#64;CO7 redis]# ./bin/redis-cli
//检查网络是否可以
127.0.0.1:6379> ping
PONG
//设置一个键值对
127.0.0.1:6379> set name cheny
OK
//获取刚刚设置的键值对
127.0.0.1:6379> get name
"cheny"
//查看所有的键
127.0.0.1:6379> keys *
1) "name"
//删除name这个键
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>