Redis commonly used basic configuration and common commands

Insert picture description here
1. daemonize: Set Redis to run in the background

Edit the redis configuration file:

命令:vim redis.comf

Locate to line 136 of the configuration file, change "no" to "yes", and then: "wq" save and exit the
background operation can be realized after the configuration is complete
Insert picture description here
. 2. port: set the port number

First, we first run the redis service as a background process:

Command: ./src/redis-server redis.conf

Enable redis-cli command after starting redis

./src/redis-cli

Insert picture description here
How to exit, redis-cli status:

命令:exit --> 退出

There are two ways to close the background running state of redis. The kill command is too simple and rude. can use:

命令:# ./src/redis.cli shutdown -->更加安全的关闭redis进程

Redis port (port) setting: (It is not recommended to use the default port, it is easy to be attacked by hackers)

vim redis.conf --> Enter redis.conf file, press "i" key to enter edit mode

Locate line 92:
Insert picture description here
After restarting, you can see the port number change
Insert picture description here

Three. logfile: Set the log file

Locate to line 171-"Log information settings (the log file saves the output information of the bottom layer of redis) After
Insert picture description here
the configuration file is modified and saved, restart redis

–>Command#: ./src/redis-server redis.conf

After successful startup, if you try to connect to redis using the redis client (redis.cli), an error will be reported. The reason is -> We have modified the access port of redis above.

The correct connection method is-command #: ./src/redis.cli -p + new port number four, databases: set the total number of
Insert picture description here
databases

Redis database operation command -> select redis database

In the state of redis connection (#./src/redis cli -p 6380)

Command: select database number (default starting from "0", there are 16 in total (the number of the last redis database is 15))

Expand the number of redis databases: need to be set in the redis.conf configuration file

Locate to line 186. After the
Insert picture description here
modification is completed, save and exit. Then close the redis background operation and restart

Shutdown command: # ./src/redis-cli -p 6380 shutdown

Connection command: # ./src/redis-server redis.conf

Five. requirepass: set the password

Identity verification is supported in redis: modify the redis.conf configuration file.

Positioning: 507 lines
Insert picture description here
, still after programming, wq–>save and exit

Then, after closing the connection, re-establish the connection
Insert picture description here
. VI. dir: Set the data file storage directory

Modify the data storage location:
Insert picture description here
Redis hard disk backup file to prevent data loss when the system is down.
Insert picture description here
Common commands:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_36792120/article/details/113210254