Window writes redis service startup script

In daily work, I always forget to turn on theredis service every time I start a project, and receive an error for the first project of the day, and then go through tedious files to find the directory where redis is located. And click redis-server.exe to start the service, so I was thinking that it would be nice to write a script on the desktop to start it with one click.

1. The directory where redis is located

Find the directory where the redis service is located and start writing the startup script.
Insert image description here

2. The script is as follows:

:: 闭命令行窗口的输出,让脚本更加简洁。
@echo off
:: redis安装目录
set REDIS_HOME=/d D:\developService\redis

cd %REDIS_HOME%
:: 启动项目
redis-server redis.windows.conf

Paste directly intobat file and modify the redis installation directory to use. The basic concepts in the script will be explained below. Friends who want to know more can pay more attention!

3. A little bit of knowledge

1、@echo

@echo is a command in the BAT script, used to control the output of the command line window. Its function is to close or open the echo function of the command line
window, thereby controlling whether the command line window displays the executed command.

To put it simply, the @echo off command will not display the execution command on the command line window, which can make the output of the BAT script clearer and avoid outputting too much useless information.
For example:

@echo off
Insert image description here
@echo on
Insert image description here
Therefore, select on or off by requirement.

2, /d reference number
set REDIS_HOME=/d D:\developService\redis
cd %REDIS_HOME%

This command can be split into the following for easier understanding:

set REDIS_HOME=D:\developService\redis
D:
cd %REDIS_HOME%

Then why do we add the parameter /d before the redis installation directory?

In Windows CMD, if you want to enter a folder under another drive letter, you need to use the /d parameter. This is because in CMD, by default, operations can only be performed under the current drive letter. If you want to switch to a folder under another drive letter, you need to use the /d parameter, otherwise CMD will not switch to the drive letter.

Since the author's script command is placed on the desktop, that is, under C盘, and redis is installed under D盘, all switching directories appear. In the case of crossing drive letters, for convenience, I chose the first method of adding /d parameters and entered the redis directory.

For example:
Insert image description here

3、::

As the name suggests,:: means a comment in the bat script file, explaining each line of command.

Summarize

Learn a little bit of knowledge every day, I hope everyone will make progress every day, and I hope this article can help everyone.

Guess you like

Origin blog.csdn.net/qq_50661854/article/details/131138409