Installation Guide for Redis and PHP Redis Extensions on Windows Systems

Author : YDD This article has 1455 words, Reading time 4 minutes Posted on: 2024-03-24 Read by 875 people
advertising chart
advertising chart
Want to show up here too?Contact us.

Article Description:

Redis最新版下载链接:https:\\www.github.com\dmajkic\redis\downloads。请根据您的机器系统选择合适位数的软件包进行下载,并将其复制到自定义的文件夹(例如“C:\redis”)以便后续操作处理。
启动一个命令提示符窗口,通过“cd”命令进入“C:\redis”目录后执行“redis-server.exe redis.conf”。如需便捷操作,建议将 Redis 的路径添加至系统环境变量,以减少手动输入路径。
接着启动新的命令提示符窗口,保持第一个窗口开启,以便随时访问服务器端。
在此窗口中运行“redis-cli.exe -h 127.0.0.1 -p 6379”命令。
创建一个名为“myKey“的键值对,输入指令“SET myKey abc”后回车。
读取该键值对,输入“GET myKey”后回车。
至此,您已在命令行上成功设定与获取 Redis 中的键值对。现在让我们尝试在 PHP 代码中实现相同功能。
以下是一段示例 PHP 代码:
<?php
//实例化 Redis 对象
$redis = new Redis();
//连接 Redis 服务(此处指的是服务器内核,并非服务器整体)
$redis->pconnect(‘127.0.0.1’, ‘6379’);
//设置带有指定名称和值的键值对
$redis->set($key, $value);
//查询之前设定的键值对
echo $redis->get($key);
//断开与 Redis 服务的连接
$redis->close();
?>
遵照上述步骤,我们便完成了 Redis 在 PHP 中的集成过程。请注意,上述代码可能会在执行过程中出现错误提.示,这通常是由于尚未安装正确的 Redis 扩展引起的。
Redis 是一款强大的开源数据库程序,采用 ANSI C 语言编写,支持网络存储及持久化日志记录工作模式。同时,它也为众多主流编程语言提供了 API 接口支持,如 Java、C/C++、C#、PHP、JavaScript、Perl、Object-C、python、Ruby、Erlang 等等。本文档介绍了如何在 Windows 操作系统下安装并配置 Redis 服务以及如何在 PHP 中使用 Redis 网络数据库服务。

请您首先检查当前PHP环境的版本,以便确立所需拓展文件的版本。随后,参照以下两个网站进行下载操作:
1、http://windows.php.net/downloads/pecl/snaps/redis/2.2.5/
2、http://windows.php.net/downloads/pecl/releases/igbinary/1.2.1/
分别对下载的rar文件进行解压,并将其中包含的python_igbinary.dll及php_redis.dll复制到相应的ext目录中。

接下来需要对php.ini文件进行配置。在此文件中增添两句语句:
extension = php_igbinary.dll
extension = phpi_redis.dll
须特别提醒的是,务必保证“extension = php_igbinary.dll”这句位于“extension = php_redis.dll”之前,否则将导致拓展功能无法正常启用。

完成上述更改后,重新启动您的Web服务器。若成功重启,则可在phpinfo页面中查找redis拓展的相关信息,由此确认redis拓展成功安装。

运行最初测试的那段代码,将能看到预期效果。
需要注意的是,无论何种情况,都不应关闭黑窗口,您的电脑正在扮演服务端角色。

advertising chart
advertising chart
Want to show up here too?Contact us.
Frequently Asked Questions FAQ
Can free downloads or VIP member-only resources be commercialized directly?
The resources on this site are collected and organized through the network, for personal research and study purposes only. The copyright belongs to the legal owner of the software and program code, users should verify the copyright and legality of the resources, prohibited for commercial use, illegal activities or any violation of national laws and regulations.
Disclaimer of liability for program or code bugs, compatibility issues or functional defects, etc.
As the resources on this site are collected and organized through the network, not the site's original, it can not fully guarantee its functionality or code compatibility. Users need to verify whether the resources meet the needs of their own, due to the following circumstances lead to losses, this site does not assume any responsibility:
Programs, source code and other computer software resources may contain code vulnerabilities (bugs), compatibility issues or functional defects left by the developer. This site does not provide free repair services for such technical defects, users need to bear the risk of debugging, modification or abandonment of the use.
© 2025 by - SourceHub & Www.ZYYdd.Com. All rights reserved 蜀ICP备2025145155号-1