您的位置:首页 > 数据库 > Redis

Windows下为PHP安装redis扩展

2017-07-15 17:19 435 查看
1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本。

2.下载php_igbinary-2.0.1-7.0-ts-vc14-x64.zip,php_redis-3.1.3rc2-7.0-ts-vc14-x64.zip(一定要保证版本的正确性)

下载地址:【选择适合的版本】
http://windows.php.net/downloads/pecl/snaps/redis/ http://windows.php.net/downloads/pecl/releases/igbinary/
ps:如果在PHP目录下看到php7ts.dll则选择ts版本



3.解压缩后,将php_redis.dll和php_redis.pdb拷贝至php的ext目录下

4.修改php.ini,(PS:此php.ini文件是在Apache目录)在该文件中加入:

; php_redis

extension=php_igbinary.dll

extension=php_redis.dll

注意:extension=php_igbinary.dll一定要放在extension=php_redis.dll的前面,否则此扩展不会生效

5.重启Apache后,使用phpinfo查看扩展是否成功安装



6.打开redis服务后,可以用如下测试是否能够调用。

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//设置 redis 字符串数据
$redis->set("tutorial-name", "Redis tutorial");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>


  ps:在运行前须开启本地的redis服务【下载地址:https://redis.io/download】

其实Redis是可以安装成windows服务的,开机自启动,命令如下:

redis-server --service-install redis.windows.conf


安装完之后,就可看到redis已经作为windows服务了:





但是安装好之后,Redis并没有启动,

启动命令如下:

redis-server --service-start


停止命令:

redis-server --service-stop


还可以安装多个实例

redis-server --service-install –service-name redisService1 –port 10001
redis-server --service-start –service-name redisService1
redis-server --service-install –service-name redisService2 –port 10002
redis-server --service-start –service-name redisService2
redis-server --service-install –service-name redisService3 –port 10003
redis-server --service-start –service-name redisService3


卸载命令:

redis-server --service-uninstall
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: