在mac 下安装redis
执行brew install redis
==> Downloading http://download.redis.io/releases/redis-2.8.19.tar.gz ######################################################################## 100.0% ==> make install PREFIX=/usr/local/Cellar/redis/2.8.19 CC=clang ==> Caveats To have launchd start redis at login: ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents Then to load redis now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist Or, if you don't want/need launchctl, you can just run: redis-server /usr/local/etc/redis.conf ==> Summary 🍺 /usr/local/Cellar/redis/2.8.19: 9 files, 824K, built in 21 seconds
然后设置开机启动
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
现在就先启动看看吧
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
现在我们就先来个hello world 吧
/usr/local/opt/redis/bin/redis-cli 127.0.0.1:6379> set name helloworld OK 127.0.0.1:6379> get name "helloworld" 127.0.0.1:6379>
停止redis
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
可以直接运行 redis-server 启动服务
redis-cli 执行客户端登录
现在就要安装phpredis扩展咯
先查看自己本机的php 版本
waken@MBP:~ $ php -v PHP 5.6.13 (cli) (built: Sep 16 2015 13:10:43) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
然后brew 安装php56-redis
waken@MBP:~ $ brew install php56-redis
可能这里,你找不到php56版本的redis扩展,可先tap
waken@MBP:~ $ brew tap josegonzalez/php
然后再运行上面的命令
在安装的时候,可能会碰到以下错误
undefined method `desc' for Formulary::Formulae::Php70:Class
则先运行
waken@MBP:~ $ brew update
然后再安装redis
最后重启php-fpm
查看phpinfo里是否有redis扩展
接下来,我们来运行php吧
<?php //Connecting to Redis server on localhost $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->set('welcome', 'hello world'); #调用方法,设置string类型值 echo $redis->get('welcome'); ?>
来源:https://www.cnblogs.com/lv-lu/p/4812218.html