PHP使用Redis。安装PHP redis 驱动,下载地址为:
https://github.com/phpredis/phpredis/releases。
设置Windows本地开机自启动服务:
redis-server --service-install redis.windows.conf
查看本地服务是否启动。使用电脑键盘上的(windows + R)键,弹出一个“运行”界面,输入“services.msc”。
查看PHP版本:
echo phpinfo();
一定要找到对应版本,搞清楚本地环境需要哪个版本的dll文件。
例如:
Compiler:MSVC11 (Visual C++ 2012)
Architecture:x86
PHP Extension Build :API20131226,TS,VC11
其中,ts是线程安全。
下载php_igbinary扩展:
https://windows.php.net/downloads/pecl/releases/igbinary/1.1.1/
下载后,将压缩包中的php_igbinary.dll文件放入,PHP安装目录中的ext目录。
下载php_redis扩展,下载地址:
https://windows.php.net/downloads/pecl/releases/redis/2.2.7/
下载后,将压缩包中的php_redis.pdb和php_redis.dll文件放入PHP安装目录下的ext目录。
配置php.ini。在php.ini文件中按照如下顺序(!)加入两行:
extension=php_igbinary.dll
extension=php_redis.dll
重启apache。
开启redis服务:
redis-server.exe redis.windows.conf
PHP中使用:
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('test','码工');
echo $redis->get('test');
领取专属 10元无门槛券
私享最新 技术干货