1. Install gcc
1. The installation of Redis on linux must first install gcc, which is used to compile the source files of redis. First you need to switch to root user
2. Then start installing gcc:
yum install gcc-c++
2. Install redis
1. First go to the official website to download the Redis compressed package, address: http://redis.io/download
2. Use the remote management tool to copy the compressed package to the Linux server and perform the decompression operation:
tar zxvf redis-4.0.8.tar.gz
3. Enter the redis decompression directory and compile:
cd redis-4.0.8
make
4. Enter the src directory and test whether the installation is successful
cd src
make test
Prompt to install TCL:
5. Install tcl:
Download: http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
Upload to linux, decompress: tar zxvf tcl8.6.1-src.tar.gz
Install tcl:
cd tcl8.6.1
cd unix/
./configure
make #compile the package
make install #install package
6. Test again whether redis is installed successfully:
cd /opt/redis-4.0.8/src
make test
7. Install to the installation path:
make PREFIX=/usr/local/redis install
8. Go to the bin directory to view:
cd /usr/local/redis
cd bin
9. Copy the redis.conf file under the decompressed redis path to the installation path
cd /opt/redis-4.0.8
cp redis.conf /usr/local/redis
cd /usr/local/redis
ls
10、启动redis
1)第一种方法:进入安装路径下的bin启动
cd /usr/local/redis/bin
./redis-server
#但是这属于前端启动,启动redis之后,我们的控制台就不能进行任何操作了。只能ctrl+c停止启动。
2)第二种方式:后端启动
cd /usr/local/redis
vi redis.conf
找到daemonize no将其改为yes:
esc退出insert模式 输入 :wq 保存修改
再次启动:
cd /usr/local/redis
./bin/redis-server ./redis.conf
这样redis就启动了。
11、查看redis是否启动:
ps -ef | grep redis
12、关闭redis
cd /usr/local/redis
./bin/redis-cli shutdown
redis简单使用:
1 //首先链接客户端
2 [root@localhost redis]# ./bin/redis-cli
3 //检查网络是否可以
4 127.0.0.1:6379> ping
5 PONG
6 //设置一个键值对
7 127.0.0.1:6379> set name cheny
8 OK
9 //获取刚刚设置的键值对
10 127.0.0.1:6379> get name
11 "cheny"
12 //查看所有的键
13 127.0.0.1:6379> keys *
14 1) "name"
15 //删除name这个键
16 127.0.0.1:6379> del name
17 (integer) 1
18 127.0.0.1:6379> keys *
19 (empty list or set)
20 127.0.0.1:6379>