PHP使用redis扩展php
一.php安装redis扩展
1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本
2.根据PHP版本号,编译器版本号和CPU架构,redis
选择php_redis-2.2.5-5.6-ts-vc11-x64.zip和php_igbinary-1.2.1-5.5-ts-vc11-x64.zip
下载地址:windows
http://windows.php.net/downloads/pecl/releases/redis/2.2.7/架构
http://windows.php.net/downloads/pecl/releases/igbinary/2.0.1/函数
3.解压缩后,将php_redis.dll和php_igbinary.dll拷贝至php的ext目录下
4.修改php.ini,在该文件中加入:.net
; php_redisserver
extension=php_igbinary.dllblog
extension=php_redis.dllip
注意:extension=php_igbinary.dll必定要放在extension=php_redis.dll的前面,不然此扩展不会生效
5.重启Apache后,使用phpinfo查看扩展是否成功安装
新建一个test.php页面get
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('test','hello redis');
echo $redis->get('test');
?>
hello redis
6. 要在Windows中使用redis须要下载Windows版的redis软件
7. 在windows中让redis开机自启动:
redis-server --service-install redis.windows-service.conf --loglevel verbose