一、安装Windows Redis环境
1、下载Redis 安装包
https://github.com/MicrosoftArchive/redis/releases
2、解压缩包,计算机指定的磁盘下
在该路径下 加入 Windows 注册服务,并启动服务等命令。。。
redis-server.exe --service-install redis.windows.conf --service-name redis --loglevel verbose 安装服务
redis-server.exe --service-start --service-name redis 启动服务
redis-server.exe --service-stop --service-name redis 停止服务
redis-server.exe --service-uninstall --service-name redis 卸载服务
检查是否成功: 看下 Windows 服务 中是否有 redis 服务并且 是否已经启动。
二、安装PHP-Redis 扩展
1、首先查看phpinfo 查看 自己PHP 版本的 位数、编译器版本、nts/ts 区别。
https://windows.php.net/downloads/pecl/releases/igbinary/2.0.1/
https://windows.php.net/downloads/pecl/releases/redis/2.2.7/
下载对应的版本
2、解压缩后,将php_redis.dll和php_igbinary.dll拷贝至php的ext目录下
3、修改php.ini,(PS:此php.ini文件是在Apache目录)在该文件中加入:
; php_redis
extension=php_igbinary.dll
extension=php_redis.dll
注意:extension=php_igbinary.dll一定要放在extension=php_redis.dll的前面,否则此扩展不会生效
4、重启Apache后,使用phpinfo查看扩展是否成功安装
5、用PHP 代码测试
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set("test", "123123");
echo $redis->get("test");
?>
注:若出现
Fatal error: Uncaught exception 'RedisException' with message 'protocol error, got '<' as reply type byte ' 这个错误,
是由于Windows PHP-Redis 服务未启动。。