Redis study concluded (nine) - Redis General Tips

Here it will record Redis common tips

Global use redis-clicommands such as

Before we are doing at Redis commands directory by ./redis-cliaccessing this form, if you use redis-cliwill be reported if the command does not recognize the error:

-bash: redis-cli: command not found

Setting method:

1) Edit /etc/profilethe file

[root@VM_0_15_centos redis4]# vim /etc/profile

2) adding to Redis installation directory PAHTpath

export PATH=$JAVA_HOME/bin:/usr/local/ruby/bin:$PATH:/usr/local/redis/redis4

3) refresh configuration

[root@VM_0_15_centos redis4]# source /etc/profile

4) perform any directory redis-clicommand

# 返回根目录
[root@VM_0_15_centos redis4]# cd /
# 启动服务
[root@VM_0_15_centos /]# redis-server /usr/local/redis/redis4/config/redis-7000.conf
# 客户端连接 
[root@VM_0_15_centos /]# redis-cli -p 7000

Remote Connection

Redis allows only local connections by default, if you need to start a remote connection, then you need to edit redic.confto modify the following two configurations:

1) Notes Binding Machine Access

# bind 127.0.0.1 # 

2) After redis3.2 also configure protected-mode

protected-mode no

Prohibit the use of command

In a production environment disable some dangerous commands, such as:

  • flushdb: Empty database
  • flushall: clear all records, databases
  • config: The client can configure the server connection
  • keys: The client connection can view all existing keys

Disable way

In redis.confFind the configuration file SECURITYoptions, add the following command:

rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
rename-command KEYS ""

If you want to keep order, but can not easily use, you can rename command set:

rename-command FLUSHALL adsfdsafsfsdfdsf1
rename-command FLUSHDB adsfdsafsfsdfdsf2
rename-command CONFIG adsfdsafsfsdfdsf3
rename-command KEYS adsfdsafsfsdfdsf4

After this restart the server, you need to use a new command to perform the operation or the server will complain unknown command. For the FLUSHALLcommand, you need to set the configuration file appendonly no, otherwise the server does not start

Guess you like

Origin www.cnblogs.com/markLogZhu/p/11421879.html