一、Redis介绍
Redis 是用C语言开发的一个开源的高性能键值对数据库。它通过提供多种键值对数据类型来适应不同场景下的存储需求,目前Redis支持的键值数据类型如下:
- 字符串类型
- 散列类型
- 列表类型
- 集合类型
- 有序集合类型
二、安装
下载地址:wget http://download.redis.io/releases/redis-4.0.9.tar.gz
1、将安装包上传到linux
alt+p//进入sftp模式进行上传
put G:/redis-3.0.0.tar.gz
2、进行编译,编译依赖于gcc环境,所以先安装gcc环境
yum install gcc-c++
3、解压软件
tar -zxvf redis-3.0.0.tar.gz
4、进入文件夹然后执行make进行编译
cd redis-3.0.0
make
5、安装
make PREFIX=/redis install
6、查看bin文件
redis-benchmark | 性能测试工具 |
redis-check-dump | RDB文件检查工具 |
redis-check-aof | AOF文件修复工具 |
redis-cli | 命令行客户端 |
redis-server | redis服务器启动命令 |
7、copy 配置文件
[root@host01 redis-3.0.0]# cp redis.conf /redis/
[root@host01 redis-3.0.0]# cd /redis/
[root@host01 redis]# ls
bin redis.conf
三、Redis的启动模式
1、前端启动模式
直接运行bin/redis-server启动前端模式,该方式的缺点是启动完成后,不能再进行其他操作,如果要进行只能ctrl+C,同时redis-server也被停止
2、后端模式
修改redis.conf配置文件,修改第37行daemonize yes
3、每次启动指定配置文件
[root@host01 redis]# ls
bin redis.conf
[root@host01 redis]#
bin/redis-server redis.conf
[root@host01 redis]# ps -ef |grep -i redis
root 3163 1 0 04:51 ? 00:00:00 bin/redis-server *:6379
root 3169 2739 0 04:51 pts/0 00:00:00 grep -i redis
绑定ip方式连接
连接后面加上-h 192.168.10.110
./bin/redis-cli -h 192.168.10.110
4、停止服务
./bin/redis-cli shutdown
四、测试
1、向Redis服务发送命令
[root@host01 redis]# ./bin/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
2、设置获取及删除数据
127.0.0.1:6379> set name tom
OK
127.0.0.1:6379> get name
"tom"
127.0.0.1:6379> del name
(integer) 1