Summary of Redis installation and usage

  • 2020-06-03 08:45:06
  • OfStack

This paper summarizes the installation and use of Redis. To share for your reference, specific as follows:

1. Download:

Address of the project: https: / / github com/MSOpenTech/redis

Download address: https: / / github com/MSOpenTech/redis/releases

Note that to download zip, do not download msi.

2. Installation:

Unzip it, copy it to the e root directory, rename the folder redis (eliminate version number and so on), and complete the installation.

3. Startup:

Open cmd, enter redis, and enter the command redis-server.exe  redis.windows.conf , enter, that is, the startup is complete.

A square box pattern appears, even if started successfully.

Otherwise the startup fails.

In the development environment, cmd can only be started successfully if you open it as an administrator. If it's a server environment, which is itself an administrator, you don't need to do this specifically.

4. Test:

Open another cmd, enter redis, enter the command ES49en-ES50en.exe, enter, enter redis operation state.

The input set age 21 , returns OK, indicating a successful write.

The input get age , will return 21, indicating that the value is successful.

The test is complete.

If the connection is not local, or the port has been changed and you find it cannot be connected, you should do this:

New port number for host IP-p

For example, if the port has been changed to 666, write:


redis-cli.exe -p 666

So you can connect it

5. Persistence:

1) AOF:

Modified in ES84en.windows.conf:


appendonly yes

It will generate an ES90en.aof file, also known as a log file, under the program folder, where the data will be stored.

(2) RDB:

By default, a data snapshot named dump. rdb is created under the programs folder. The snapshot logic is as follows:


#900 Seconds later and at least 1 a key Snapshots are created when changes occur 
save 900 1
#300 Seconds later and at least 10 a key Snapshots are created when changes occur 
save 300 10
#60 Seconds later and at least 10000 a key Snapshots are created when changes occur 
save 60 10000

You can disable snapshot creation by commenting out save.

What is RedisQFork?

This is the memory map for redis, which creates a file when redis is started and disappears when it is closed. This file just writes the data in memory and makes a mapping.

The more data the bat gets, the bigger it is and the more space it takes up on the c disk. The solution is to change the path to another disk.

Note: heapdir was not found in the 3.2 version I downloaded, and I set heapdir e:\redis\ and the launch will report an error, unknown parameter heapdir, and the entire computer can not find the RedisQFork file, I suspect the new VERSION of redis has abandoned this mapping.

To test the 2.8 download, there is indeed an heapdir option.

6. Startup:

Configure redis as a service:

Open cmd as administrator, enter e disk, and type:

E:\redis\redis-server.exe --service-install E:\redis\redis.windows.conf --loglevel verbose

Press enter and the service is created.

Can open run - services.msc - You can see Redis service.

Restart the computer and Redis has started. You can turn on the redis-ES148en test.

Delete service:


E:\redis\redis-server --service-uninstall

7. Safety

redis. windows. conf

(1) the binding ip

It can be local or external, which is usually bound by default (redis3.2).


bind 127.0.0.1

Modify the default port

Change the default 6379 to another port

Disable dangerous commands

Setting it to "" disables the following command:


rename-command FLUSHALL ""
rename-command CONFIG ""
rename-command EVAL ""

8, through the command line fuzzy query

If we determine an key, the query will look like this:


get xxx

If we only know that the prefix key is test, we can do this:


keys test*

You can use * and ? To match the fuzzy parts.

9. Expiration time

php Using redis to write the expiration time 1 must be mandatory for (int) type, neither string nor double, only int can.

I hope this article has been helpful to the Redis database programming.


Related articles: