使用Homebrew安装redis可以减少大量的安装和配置的工作量。

一、首先安装redis

[html] view plain copy
  1. brew install redis  

安装完成后的提示信息

在mac上通过brew安装redis以及phpRedis扩展

开机启动redis命令 

[html] view plain copy
  1. ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents  
使用launchctl启动redis server

[html] view plain copy
  1. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist  
使用配置文件启动redis server

[html] view plain copy
  1. redis-server /usr/local/etc/redis.conf  
停止redis server的自启动

[html] view plain copy
  1. launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist  
redis 配置文件的位置 

[html] view plain copy
  1. /usr/local/etc/redis.conf  
卸载redis和它的文件

[html] view plain copy
  1. brew uninstall redis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist  
测试redis server是否启动

[html] view plain copy
  1. redis-cli ping  

二、安装完redis以后,再安装phpredis扩展(全都是Mac上安装)

[plain] view plain copy
  1. brew install php70-redis #这里根据你的PHP版本决定,我的是php70,所以安装php70的扩展  

编辑你的php.ini,再最后添加上下面代码:

[html] view plain copy
  1. extension=redis.so  

重启你的php-fpm

[html] view plain copy
  1. sudo killall php-fpm #关闭php-fpm  

[html] view plain copy
  1. 这是我的启动php-fpm方式  
  2. cd /usr/local/Cellar/php70/7.0.26_18/sbin/sudo  
  3. ./php70-fpm start  

检查是否有redis扩展

[html] view plain copy
  1. php -m | grep redis  
最后PHP测试代码:

[php] view plain copy
  1. <?php  
  2.   
  3. $redis = new redis();  
  4. $redis->connect('127.0.0.1', 6379);  
  5. $redis->set('test',"11111111111");  
  6. $result = $redis->get('test');  
  7. var_dump($result);  
浏览器显示出下图表示安装成功:

在mac上通过brew安装redis以及phpRedis扩展



相关文章: