Home Backend Development PHP Tutorial Summary of Redis installation and usage methods

Summary of Redis installation and usage methods

Apr 13, 2018 pm 03:44 PM
redis Instructions

This article mainly introduces the installation and use of Redis, and analyzes the download, installation, startup, settings and related operating instructions of the Redis database in the form of examples. Friends in need can refer to it

The examples in this article summarize the installation and use of Redis. Share it with everyone for your reference, the details are as follows:

1. Download:

Project address: https://github.com/MSOpenTech /redis

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

Note, download the zip version, not the msi version.

2. Installation:

Unzip, copy to the root directory of the e drive, and rename the folder to redis (remove the version number and the like) ), the installation is completed.

3. Start:

Open cmd, enter redis, enter the command redis-server.exe redis.windows.conf, press Enter, the startup is completed.

A square box pattern appears even if the startup is successful.

Otherwise the startup fails.

In the development environment, cmd must be opened as an administrator to start successfully. If it is a server environment and you are the administrator, you do not need to do this in particular.

4. Test:

Open another cmd, enter redis, enter the command redis-cli.exe, and press Enter to enter redis operating status.

Enter set age 21, and OK will be returned, indicating that the writing is successful.

Enter get age, and 21 will be returned, indicating that the value is successfully obtained.

Finished test.

If the connection you want to connect is not local, or the port has been changed, and you find that you cannot connect, you should do this:

redis-cli.exe -h host IP -p new port number

For example, assuming the port has been changed to 666, then it should be written like this:

redis-cli.exe -p 666
Copy after login

This way you can connect

5. Persistence:

① AOF:

Modify in redis.windows.conf:

appendonly yes
Copy after login

That’s it. An appendonly.aof file will be generated in the program folder, which is a log file, and the data will be stored in this file.

② RDB:

By default, a data snapshot named dump.rdb will be created in the program folder. The logic of the snapshot is as follows:

#900秒后且至少1个key发生变化时创建快照
save 900 1
#300秒后且至少10个key发生变化时创建快照
save 300 10
#60秒后且至少10000个key发生变化时创建快照
save 60 10000
Copy after login

You can disable the creation of snapshots by commenting out save.

③ What is RedisQFork.dat:

This is the memory mapping of redis. When redis starts, such a file will be created. When redis is closed, this file will be created. And it disappeared. This file is to write the memory data into it and make a mapping.

The more data there is, the larger the bat will be, which will occupy the space of the c drive. The solution is to change the path to another drive.

Note: The 3.2 version I downloaded did not find the heapdir, and I set it myself heapdir e:\redis\ Then an error will be reported when starting, the unknown parameter heapdir, and the entire The computer cannot find the RedisQFork file. I suspect that the new version of redis has abandoned this mapping.

For testing, I downloaded version 2.8, which does have the heapdir option.

6. Start up:

Configure redis as a service:

Open cmd as administrator and enter e disk, enter:

Copy code The code is as follows:

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

Press Enter and the service is created.

You can open and run -services.msc-you can see the Redis service.

Restart the computer and Redis has been started. You can open redis-cli testing.

Delete service:

E:\redis\redis-server --service-uninstall
Copy after login

##7. Security

Modify in

redis.windows.conf:

① Binding ip

can be local or External network, this is generally bound by default (redis3.2)

bind 127.0.0.1
Copy after login

② Modify the default port

Default Change 6379 to other ports

③ Disable dangerous commands

Set it to "" to disable the following commands:

rename-command FLUSHALL ""
rename-command CONFIG ""
rename-command EVAL ""
Copy after login

8. Fuzzy query through command line

If we determine a key, the query will be like this:

get xxx
Copy after login

If we only know that the prefix of this key is test, then it can be like this:

keys test*
Copy after login

You can use * and ? to match ambiguous parts.

9. Expiration time

#When using redis to write the expiration time in php, it must be forced to be of type (int), whether it is string or double. No, only int can.

related suggestion:

php cache example using redis

Partial summary of Redis commands in PHP

The above is the detailed content of Summary of Redis installation and usage methods. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 May 08, 2024 pm 03:50 PM

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100

How to change the password in redis How to change the password in redis Apr 20, 2024 am 03:00 AM

How to change the password in redis

Analyze PHP function bottlenecks and improve execution efficiency Analyze PHP function bottlenecks and improve execution efficiency Apr 23, 2024 pm 03:42 PM

Analyze PHP function bottlenecks and improve execution efficiency

Is redis a memory cache? Is redis a memory cache? Apr 20, 2024 am 05:26 AM

Is redis a memory cache?

Golang API caching strategy and optimization Golang API caching strategy and optimization May 07, 2024 pm 02:12 PM

Golang API caching strategy and optimization

Is redis a non-relational database? Is redis a non-relational database? Apr 20, 2024 am 05:36 AM

Is redis a non-relational database?

Which one has better performance, erlang or golang? Which one has better performance, erlang or golang? Apr 21, 2024 am 03:24 AM

Which one has better performance, erlang or golang?

Caching mechanism and application practice in PHP development Caching mechanism and application practice in PHP development May 09, 2024 pm 01:30 PM

Caching mechanism and application practice in PHP development

See all articles