本文主要是mac环境下如何配置redis服务。
一、首先是官网下载redis
![](http://upload-images.jianshu.io/upload_images/5391552-1b78cc5e8f38c973.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
下载 stable 版本,稳定版本。
![](http://upload-images.jianshu.io/upload_images/5391552-46c774c70f933abe.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
二、安装与编译
先找到usr/local目录,也可以直接命令行完成,建议windows可以这样操作,自己mac系统直接命令行出现了错误,找不到改目录,于是手动移动安装目录。
主要分为两步,先是打开访达,command+shift+G跳转目录。
![](http://upload-images.jianshu.io/upload_images/5391552-ba5ee5a4fae8c365.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
然后使用一下解压命令,或手动解压到该路径下。
![](http://upload-images.jianshu.io/upload_images/5391552-84562c14f358d913.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
- 解压:
tar zxvf redis-4.0.10.tar.gz
- 移动到:
mv redis-4.0.10 /usr/local/
- 切换到:
cd /usr/local/redis-4.0.10/
- 编译测试
sudo make test
- 编译安装
sudo make install
三、安装成功测试
1.安装成功后,输入redis-server
启动redis
![](http://upload-images.jianshu.io/upload_images/5391552-25722ffb12fde013.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
2.测试redis
新建一个终端窗口,输入命令行redis-cli
![](http://upload-images.jianshu.io/upload_images/5391552-c8901dd04c4db698.png?imageMogr2/auto-orient/strip|imageView2/2/w/1130/format/webp)
图片.png
四、安装redis客户端
redis客户端在官网是要收费的,好在作者也是比较良心,开源了项目,可以去github上下载测试版。
ps:需要自己编译,不想麻烦的可以在网上找别人编译好的
![](http://upload-images.jianshu.io/upload_images/5391552-c7d16f8f36ccc5f4.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
因为这是前台开启的,如需推出服务直接在启动窗口command+C即可
![](http://upload-images.jianshu.io/upload_images/5391552-6d8b00f2910f65d2.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
又或者可以在客户端执行 SHUTDOWN 可关闭 redis 服务。
如果关闭不了就加一个参数,执行 SHUTDOWN NOSAVE
可关闭 redis 服务
![](http://upload-images.jianshu.io/upload_images/5391552-53d2d62ada1335da.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
图片.png
测试连接,会显示服务已停止。
![](http://upload-images.jianshu.io/upload_images/5391552-c9c98382b4bc9548.png?imageMogr2/auto-orient/strip|imageView2/2/w/1192/format/webp)
图片.png
五、redis常用命令
命令 | 用途 |
---|---|
set key value | 设置 key 的值 |
get key | 获取 key 的值 |
exists key | 查看此 key 是否存在 |
keys * | 查看所有的 key |
flushall | 消除所有的 key |
本次使用的是默认的启用方式,下次做一下启动Redis并加载配置文件方式。
来源:简书 https://www.jianshu.com/p/bb7c19c5fc47