“This is the 18th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021.”

Configure the password for Redis

When we want to password protect our Redis, we can do so by modifying the configuration file or using the config command.

Configuration file Mode

Path to the configuration file: /etc/redis.conf

[root@RLKJ-BT ~]# cat /etc/redis.conf | grep requirepass
# If the master is password protected (using the "requirepass" configuration
 requirepass "pwd@123"
[root@RLKJ-BT ~]#
Copy the code

As shown above, change the requirePass field to your desired password and restart the Redis service.

Connect to redis tests

Test after entering the password

Command mode

Config set requirepass < PWD >

127.0.0.1:6379> config set requirepass pwd@321
OK
127.0.0.1:6379> exit
[root@RLKJ-BT ~]# redis-cli
127.0.0.1:6379> set name phyger
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth pwd@321
OK
127.0.0.1:6379>
Copy the code

Redis backup restore

Simple, we usually use the save command to save the data on the disk for backup. When we need to restore, we only need to move the dump. RDB file backed up in the installation directory to the installation directory of the redis instance to be restored and restart the Redis service.

When there is a large amount of data, we can use the bgsave command to make Redis backup in the background.

Common Redis command

The command use
info Query information about Redis
save Data is saved to dump. RDB in the installation directory
bgsave Data saving operations are performed in the background
lastsave Returns the last saving time
config get dir Query the Redis installation directory
client list Example Query the client list
command Query all commands and subcommands
command count Querying the Total number of commands
dbsize Query all keys
flushall Delete all keys from all db databases
flushdb Delete all keys of the current DB
monitor Real – time print Redis server received command, debugging
role Returns the role to which the primary and secondary instances belong
config set parameter value Modify redis configuration parameters without restart
time Returns the current server time
select <db_num> The db switch

See the redis documentation for more commands.