使用Homebrew安装redis可以减少大量的安装和配置的工作量。
一、首先安装redis
- brew install redis
安装完成后的提示信息
开机启动redis命令
- ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
- redis-server /usr/local/etc/redis.conf
- launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
- /usr/local/etc/redis.conf
- brew uninstall redis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
- redis-cli ping
二、安装完redis以后,再安装phpredis扩展(全都是Mac上安装)
- brew install php70-redis #这里根据你的PHP版本决定,我的是php70,所以安装php70的扩展
编辑你的php.ini,再最后添加上下面代码:
- extension=redis.so
重启你的php-fpm
- sudo killall php-fpm #关闭php-fpm
- 这是我的启动php-fpm方式
- cd /usr/local/Cellar/php70/7.0.26_18/sbin/sudo
- ./php70-fpm start
- php -m | grep redis
- <?php
- $redis = new redis();
- $redis->connect('127.0.0.1', 6379);
- $redis->set('test',"11111111111");
- $result = $redis->get('test');
- var_dump($result);