在CentOS7上安装Redis
China
在CentOS7上安装Redis
Redis在Linux上安装和简单的使用
yum安装过程
1 2 3 4
| # 快速安装redis yum install redis -y systemctl start redis systemctl enable redis
|
编译 安装过程
使用时请查看最新版本号自己更新
1 2 3 4
| wget http://download.redis.io/releases/redis-5.0.6.tar.gz tar xzf redis-5.0.6.tar.gz cd redis-5.0.6 make
|
编译检查 执行下检查以免出现问题
最后出现 绿色的 \o/ All tests passed without errors!表示检查通过没有错误
安装
1
| make PREFIX=/usr/local/redis install
|
配置项目
1 2 3
| cd .. cp redis.conf /usr/local/redis ls /usr/local/redis
|
启动Redis
第一种方法:默认配置前台启动
1
| /usr/local/redis/bin/redis-server
|
第二种方法: 后台隐藏启动
1
| vim /usr/local/redis/redis.conf
|
找到daemonize no将其改为yes(在vim中插入数据按键盘上的i或者insert)
按esc退出insert模式,再按:并且输入wq 最后回车 表示保存并且退出
再次启动
1
| /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
|
查看是否启动
关闭redis
1
| /usr/local/redis/bin/redis-cli shutdown
|
简单的使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| //首先链接客户端 /usr/local/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>
|