Home > Backend Development > PHP Tutorial > Install and use Redis and its PHP extension under Windows

Install and use Redis and its PHP extension under Windows

伊谢尔伦
Release: 2016-11-26 14:30:26
Original
1040 people have browsed it

1. Install redis under windows and test it

redis download address: https://github.com/dmajkic/redis/downloads

The downloaded Redis supports 32bit and 64bit. Choose according to your actual situation, I choose 32bit. Copy the 32bit file contents to the directory that needs to be installed, such as: D:devredis-2.4.5.

Open a cmd window, use the cd command to switch to the specified directory (D:devredis-2.4.5) and run redis-server.exe redis.conf. After running, the following interface will appear:

Install and use Redis and its PHP extension under Windows

This means that the Redis server has been installed successfully.

Reopen a cmd window, use the cd command to switch to the specified directory (D:devredis-2.4.5) and run:

redis-cli.exe -h 127.0.0.1 -p 6379
Copy after login

where 127.0.0.1 is the local IP and 6379 is the default port of the redis server. The successful operation is as shown in the figure below. In this way, the establishment of Redis windows environment has been completed:

Install and use Redis and its PHP extension under Windows

The environment has been set up, so you have to test it. For example: store a string with the key as test and the value as hello word, and then get the key value:

Install and use Redis and its PHP extension under Windows

The hell word is correctly output, and the test is successful!

2. Installation and use of Redis extension in PHP

Download the php_redis.dll file: http://download.csdn.net/download/bluesky321/5355093

First put php_redis.dll and php_igbinary.dll into PHP ext folder, and then add the following code to the php.ini configuration file:

extension=php_igbinary.dll
extension=php_redis.dll
Copy after login

Restart the web server

Note: extension=php_igbinary.dll must be placed in front of extension=php_redis.dll, otherwise this extension will not take effect

Use:

<?php
    $redis = new Redis();
    $redis->connect(&#39;127.0.0.1&#39;,6379);
    $redis->set(&#39;test&#39;,&#39;hello redis&#39;);
    echo $redis->get(&#39;test&#39;);
?>
Copy after login

Output hello redis Success!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template