Teach you how to deploy redis services in windows

Posted by pixeltrace on Wed, 08 Dec 2021 05:38:04 +0100

1 Introduction

redis does not officially provide the installation package under windows. The windows installation package you see is the version officially maintained by Microsoft.
Why Microsoft doesn't officially provide the installation package of windows version: I guess so: because redis is single threaded and high-performance. Therefore, redis requires single thread polling. The polling mechanism of the operating system is different. In short, epoll is used for linxu polling and selector is used for window, but in terms of performance, epoll is higher than selector. Therefore, redis recommends using the linux version.
In the actual development process, we will encounter the use of redis services in windows, so this article explains redis from the perspective of windows deployment

2 Environment

  • windows operating system:

3 installation

The windows installation package is not available on the official website of redis. It can be downloaded from github. If the actual project is used, please use a stable version.

github may be due to network regulation

The following is the network disk link:
Link: https://pan.baidu.com/s/1zax2weaUUVoML9gd_ATaxw
Extraction code: qjae

After downloading, copy the compressed file to the local file. Personally, I suggest creating a new directory named Envs to store all environments.


After decompression, use CMD to enter the current folder and enter redis-server.exe. The redis service starts successfully

E:\Envs\Redis-x64-5.0.14>redis-server.exe
[7212] 08 Dec 11:54:41.453 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
[7212] 08 Dec 11:54:41.468 # Redis version=5.0.14, bits=64, commit=a7c01ef4, modified=0, pid=7212, just started
[7212] 08 Dec 11:54:41.468 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server.exe /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.14 (a7c01ef4/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7212
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[7212] 08 Dec 11:54:41.468 # Server initialized
[7212] 08 Dec 11:54:41.468 * Ready to accept connections

The CMD window will be blocked. Reopen a CMD window and cd to the redis Directory: test link

E:\Envs\Redis-x64-5.0.14>redis-cli.exe
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> exit

E:\Envs\Redis-x64-5.0.14>redis-cli.exe
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> keys *
(empty list or set)

All functions are normal

Deploy as service

Once the above CMD window is closed, the redis service will stop

Register redis as a service and give it to the operating system to run in the background.

Install as service command:

E:\Envs\Redis-x64-5.0.14>redis-server.exe --service-install redis.windows.conf
[3068] 08 Dec 12:00:47.092 # Granting read/write access to 'NT AUTHORITY\NetworkService' on: "E:\Envs\Redis-x64-5.0.14" "E:\Envs\Redis-x64-5.0.14\"
[3068] 08 Dec 12:00:47.106 # Redis successfully installed as a service.

Uninstall service

E:\Envs\Redis-x64-5.0.14>redis-server --service-uninstall
[5780] 08 Dec 12:00:17.075 # Redis service successfully uninstalled.

Other commands

Open service: redis-server --service-start

Out of Service: redis-server --service-stop

Rename service: redis-server --service-name name


Configure three different redis services using three ports

redis-server --service-install --service-name redisService1 --port 10001

redis-server --service-start --service-name redisService1

redis-server --service-install --service-name redisService2 --port 10002

redis-server --service-start --service-name redisService2

redis-server --service-install --service-name redisService3 --port 10003

redis-server --service-start --service-name redisService3

4 client commands

Simple client

redis-cli.exe

Specify parameter client

redis-cli.exe -h 127.0.0.1 -p 6379 -a requirepass
(-h server address  -p Specify the port number -a Password to connect to the database[Can be in redis.windows.conf Medium configuration],Default no password)

Note: if the environment variable is not configured, you must first CD it to the redis folder, otherwise the system will prompt you not to know the specified command

E:\Envs>redis-server.exe
'redis-server.exe' is not recognized as an internal or external command,
operable program or batch file.
# You must cd to the redis directory
E:\Envs>cd Redis-x64-5.0.14

E:\Envs\Redis-x64-5.0.14>

Topics: Windows Database Redis architecture