0
点赞
收藏
分享

微信扫一扫

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

茗越 2022-04-29 阅读 144
java后端

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

一、首先安装redis

[html] view plain copy

  1. brewinstallredis

安装完成后的提示信息

开机启动redis命令

[html] view plain copy

  1. ln-sfv/usr/local/opt/redis/*.plist~/Library/LaunchAgents

使用launchctl启动redis server

[html] view plain copy

  1. launchctlload~/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. launchctlunload~/Library/LaunchAgents/homebrew.mxcl.redis.plist

redis 配置文件的位置

[html] view plain copy

  1. /usr/local/etc/redis.conf

卸载redis和它的文件

[html] view plain copy

  1. brewuninstallredisrm~/Library/LaunchAgents/homebrew.mxcl.redis.plist

测试redis server是否启动

[html] view plain copy

  1. redis-cliping

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

[plain] view plain copy

  1. brewinstallphp70-redis#这里根据你的PHP版本决定,我的是php70,所以安装php70的扩展

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

[html] view plain copy

  1. extension=redis.so

重启你的php-fpm

[html] view plain copy

  1. sudokillallphp-fpm#关闭php-fpm

[html] view plain copy

  1. 这是我的启动php-fpm方式
  2. cd/usr/local/Cellar/php70/7.0.26_18/sbin/sudo
  3. ./php70-fpmstart

检查是否有redis扩展

[html] view plain copy

  1. php-m|grepredis

最后PHP测试代码:

[php] view plain copy

  1. <php

  2. $redis=newredis();

  3. $redis->connect(‘127.0.0.1’,6379);

  4. $redis->set(‘test’,“11111111111”);

  5. KaTeX parse error: Can't use function '\=' in math mode at position 7: result\̲=̲redis->get(‘test’);

  6. var_dump($result);

浏览器显示出下图表示安装成功:

举报

相关推荐

0 条评论