出自原文:http://anythink.com.cn/home/install-redis-in-macos.html
首先,你需要有安装Xcode 的 command Tools 才能保证编译不会出问题,试着输入make 看看是否提示命令不存在,如果没有提示命令不存在,那么应该可以安装。
1
2
3
4
5
6
7
8
9
10
|
cd /opt
curl -O http: //redis .googlecode.com /files/redis-2 .6.4. tar .gz
sudo tar -zxf redis-2.6.4. tar .gz
mv redis-2.6.4 redis
cd redis/
sudo make
sudo make test
sudo make install
cd src/
. /redis-server
|
这样就已经成功启动了redis服务,我们还需要一个配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
daemonize yes
pidfile /opt/redis/redis .pid
port 6379
timeout 300
loglevel debug
logfile /opt/redis/log-redis .log
databases 8
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /opt/redis/
appendonly no
appendfsync everysec
|
将上面的文件保存成redis.conf 放到redis目录下,然后执行命令。
1
2
3
|
sudo mv /opt/redis/src/redis-server /opt/redis/redis-server
sudo mv /opt/redis/src/redis-cli /opt/redis/redis-cli
sudo /opt/redis/redis-server redis.conf
|
ok,现在已经大功告成,你的redis已经成功运行起来了。
试试看吧!
1
2
3
4
5
|
/opt/redis/redis-cli
#会看到提示 redis 127.0.0.1:6379>说明已经连接服务。
set anythink helloworld
get anythink
exit
|
good 看到了helloworld,说明一切正常。
如果我需要停止redis或者需要重新启动呢?
1
2
3
4
|
cat /opt/redis/redis .pid
#cat后会得到一个pid,我的是44277
sudo kill 44277
# 启动方法和之前一样。
|
如果你需要在PHP中使用redis,那么请继续往下看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
curl -O https: //nodeload .github.com /nicolasff/phpredis/zip/master
tar -zxf master
cd phpredis-master/
phpize
. /configure
make
sudo make install
# 这时候会提示一个路径
# /usr/lib/php/extensions/no-debug-non-zts-20090626/
# 表示已经将扩展放置在该位置
vim /etc/php .ini
#增加如下内容
extension=redis.so
#重启apache
sudo httpd -k restart
#查看扩展安装情况
php -m | grep redis
#出现 redis 表示安装成功。
|
1
2
3
4
5
6
7
8
9
10
|
如果执行phpize提示如下错误
Cannot find autoconf. Please check your autoconf installation
and the $PHP_AUTOCONF environment variable.
Then, rerun this script.
请分别下载M4,autoconf编译安装
curl -O http: //ftp .gnu.org /gnu/m4/m4-1 .4.9. tar .gz
curl -O http: //ftp .gnu.org /gnu/autoconf/autoconf-2 .62. tar .gz
|
注意,以上使用的apache、php均为MacOS自带的,如果是自己安装的phpize请指定绝对路径。
另:redis还有一个基于WEB的图形界面管理工具,叫phpRedisAdmin,如果刚开启服务会出现一些Undefined index,过一会就好了。如果想试试可以使用如下命令安装(git推荐使用SourceTree安装)该管理工具支持String、Hash、List、Set、Zset
1
2
3
|
git clone https: //github .com /ErikDubbelboer/phpRedisAdmin .git
cd phpRedisAdmin/
git clone https: //github .com /nrk/predis .git
|