其实 Mac 安装 Redis 还是很简单,以下为个人搭建配置。
注意:文章中的“*”代表任意版本号

安装 Redis 服务

  • 安装
brew install redis
  • 使用
# 启动
redis-server

启动成功界面
Mac 安装PHP Redis 扩展
另开一个命令窗口,可以使用 Redis 命令在 redis 服务上执行操作。

redis-cli

Mac 安装PHP Redis 扩展

安装 php-redis 扩展

下文中的配置目录可根据记几个的 PHP 配置自行修改。

tar -xzvf redis-4.*.tgz
  • 通过phpize生成编译configure配置文件
cd redis-4.*/
phpize
./configure --with-php-config=/usr/local/opt/php\@7.*/bin/php-config
  • 编译
make
make install
  • 配置 php.ini文件
    /usr/local/etc/php/7.2/php.ini
extension="redis.so"
  • 测试 访问 localhost/redis.php
<?php
//实例化redis对象
$redis = new redis();
//连接redis,第一个参数是redis服务的IP127.0.0.1是自己的,6379是端口号
$redis->connect('127.0.0.1', 6379);
echo "Server is running: " . $redis->ping();

输出:Server is running: +PONG

相关文章:

  • 2021-04-04
  • 2022-01-07
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-05-28
  • 2021-09-13
  • 2021-11-28
相关资源
相似解决方案