PHP redis installation under Windows

 

 

1. Redis server download address:  https://pan.baidu.com/s/1gE59KS-pKD2bbTyhwrcL0g   Extraction code: nrug

Unzip and install, no problem, go directly to the installation steps.

1. Temporary service installation   cmd to enter the Redis installation file, start the temporary service: redis-server.exe redis.windows.conf, if a square icon appears, the temporary service installation is successful.

Note: By using the above command, a temporary Redis service will be created, and the Redis service name and status will not appear in the window Service list. When this window is closed, the service will be closed automatically. You can install a Redis Management test. When you close this temporary service, the database cannot be connected.

Now call the client, because there is only a temporary service, do not close the above window, we open the redis-cli.exe executable file in the folder, enter the client Dos window, type Set uid 1 and return OK, which means writing to the memory; If we hit Get uid again, it will return a Value of 1, as shown below:

2

2. Default service installation   It is impossible for us to open a temporary service every time we use Redis, can it be started automatically like other services? Of course it is available, but there is a difference, which will be discussed later. Enter the Redis installation package file and type in the command to register the service: redis-server.exe --service-install redis.windows.conf --loglevel verbose (the temporary service must be turned off, otherwise the installation will fail).

Obviously the service has been installed according to the English prompt. It can be seen in the window Service list, but it has not been started and cannot be started manually. Only by pressing the command to start/pause/uninstall the service: redis-server.exe --service-start; redis- server.exe --service-stop; redis-server.exe --service-uninstall.

4

3. Custom service installation The   so-called custom service installation is to rename the service. Enter the Redis installation package file and register the service: redis-server.exe --service-install redis.windows.conf --Service-name RedisServer1 --loglevel verbose

Note: By using the above command, the "redisserver1" service will appear in the window Service list, but this service is not in the started state, you need to call the following command to start the service.

Same as the default installation, the only difference is that you need to add a custom Redis service name when installing the service, starting, shutting down, and uninstalling the service: redis-server.exe --service-start --Service-name RedisServer1; redis-server .exe --service-stop --Service-name RedisServer1; redis-server.exe --service-uninstall --Service-name RedisServer1 After uninstalling the custom service through the command line, restart the computer and the uninstallation of the service will be completed.

4. Redis master-slave service installation   master-slave service can achieve load balancing, in fact, copy the above Redis installation file package to the corresponding directory, modify the IP and Port of the master and slave server configuration files, and specify the IP of the master server for the slave server , Port, according to the Redis custom service installation command for service installation, service startup, service shutdown, service uninstallation can be used.

My local master-slave server installation package is still in the D:\redis-win directory, the folder Redis-x64-3.2.100 is the main service, and the folder Redis-x64-3.2.100-2 is the slave service. It is the local IP: 127.0.0.1, you can set it according to your actual situation in the production environment.

The main server (RedisServer1) redis.windows.conf is modified as follows: port 6379 (default), no need to modify;

From the server (RedisServer2) redis.windows.conf amended as follows: port 6380; slaveof 127.0.0.1 6379, see the following figure for the modification:

We use RedisManagement to connect two ports as the client. Adding keys in the main service can be synchronized to the slave service, and adding the slave service is invalid. If the slave service is not configured with the affiliation, we can configure the slave service in the Redis manager, open the console, and enter slaveof 127.0.0.1 6379, the effect is the same.

to sum up

When we install the slave service, we can install the specified port and the specified host without using a configuration file. redis-server.exe --service-install redis.windows.conf --Service-name RedisServer2 --loglevel verbose --port 6380, this is also the designated port installation.

Run the slave service redis-cli.exe, which is the same as RedisManagement, and can also be configured with affiliation. The reason I didn’t use it was because I couldn’t get the port 6380 from the service every time I run it (still 6379), but I can connect two ports to the service in the Redis manager. I didn’t use this method. Many online tutorials say Yes, I did not succeed in practice!

Two, phpredis installation

Official download address: http://pecl.php.net/package/redis

Below I shared the download address of php7.0 nts   https://pan.baidu.com/s/133vhKRtTTr0uj6vOO2Ow0w    Extraction code: n38x

Download according to your version.

Select the corresponding download in the newly opened window, first check the phpinfo information

So here I choose the 64-bit nts version download

2. Find the php installation directory and put the two files in the downloaded package into the ext folder

3. Modify php.ini to add

extension=php_redis.dll to
enable redis extension, save and restart Nginx or Apache server
4. Verify whether redis extension is enabled

Check the phpinfo information again and search for redis, which means it is successfully started.

5.php connect and test redis database

New test.php

<?php
 $redis = new Redis();
 $redis->connect('127.0.0.1',6379); 
 $redis->set('name','leesin');
 echo $redis->get('name');
?>
访问test.php
输出 leesin

At this point, you have all completed the installation of Redis and PHP's redis extension under Windows!

Guess you like

Origin blog.csdn.net/qq_39418742/article/details/104867499