使用Homebrew安装redis可以减少大量的安装和配置的工作量。
一、首先安装redis
[html] view plain copy
- brewinstallredis
安装完成后的提示信息
开机启动redis命令
[html] view plain copy
- ln-sfv/usr/local/opt/redis/*.plist~/Library/LaunchAgents
使用launchctl启动redis server
[html] view plain copy
- launchctlload~/Library/LaunchAgents/homebrew.mxcl.redis.plist
使用配置文件启动redis server
[html] view plain copy
- redis-server/usr/local/etc/redis.conf
停止redis server的自启动
[html] view plain copy
- launchctlunload~/Library/LaunchAgents/homebrew.mxcl.redis.plist
redis 配置文件的位置
[html] view plain copy
- /usr/local/etc/redis.conf
卸载redis和它的文件
[html] view plain copy
- brewuninstallredisrm~/Library/LaunchAgents/homebrew.mxcl.redis.plist
测试redis server是否启动
[html] view plain copy
- redis-cliping
二、安装完redis以后,再安装phpredis扩展(全都是Mac上安装)
[plain] view plain copy
- brewinstallphp70-redis#这里根据你的PHP版本决定,我的是php70,所以安装php70的扩展
编辑你的php.ini,再最后添加上下面代码:
[html] view plain copy
- extension=redis.so
重启你的php-fpm
[html] view plain copy
- sudokillallphp-fpm#关闭php-fpm
[html] view plain copy
- 这是我的启动php-fpm方式
- cd/usr/local/Cellar/php70/7.0.26_18/sbin/sudo
- ./php70-fpmstart
检查是否有redis扩展
[html] view plain copy
- php-m|grepredis
最后PHP测试代码:
[php] view plain copy
-
<php
-
$redis=newredis();
-
$redis->connect(‘127.0.0.1’,6379);
-
$redis->set(‘test’,“11111111111”);
-
KaTeX parse error: Can't use function '\=' in math mode at position 7: result\̲=̲redis->get(‘test’);
-
var_dump($result);
浏览器显示出下图表示安装成功: