redis修改配置重启命令_如何从命令行更改Redis的配置

redis修改配置重启命令

介绍 (Introduction)

Redis is an open-source, in-memory key-value data store. Redis has several commands that allow you to make changes to the Redis server’s configuration settings on the fly. This tutorial will go over some of these commands, and also explain how to make these configuration changes permanent.

Redis是一个开源的内存中键值数据存储。 Redis有几个命令,可让您即时更改Redis服务器的配置设置。 本教程将介绍其中一些命令,并说明如何使这些配置更改永久生效。

如何使用本指南 (How To Use This Guide)

This guide is written as a cheat sheet with self-contained examples. We encourage you to jump to any section that is relevant to the task you’re trying to complete.

本指南以备有完整示例的备忘单形式编写。 我们鼓励您跳至与您要完成的任务相关的任何部分。

The commands shown in this guide were tested on an Ubuntu 18.04 server running Redis version 4.0.9. To set up a similar environment, you can follow Step 1 of our guide on How To Install and Secure Redis on Ubuntu 18.04. We will demonstrate how these commands behave by running them with redis-cli, the Redis command line interface. Note that if you’re using a different Redis interface — Redli, for example — the exact output of certain commands may differ.

本指南中显示的命令已在运行Redis版本4.0.9的Ubuntu 18.04服务器上进行了测试。 要设置类似的环境,您可以按照我们的指南如何在Ubuntu 18.04上安装和保护Redis的 步骤1进行操作。 我们将通过使用Redis命令行界面redis-cli运行它们来演示这些命令的行为。 请注意,如果您使用其他Redis界面(例如Redli) ,则某些命令的确切输出可能会有所不同。

Be aware that managed Redis databases typically do not allow users to alter the configuration file. If you’re working with a Managed Database from DigitalOcean, the commands outlined in this guide will result in errors.

请注意,托管Redis数据库通常不允许用户更改配置文件。 如果您正在使用DigitalOcean的托管数据库,则本指南中概述的命令将导致错误。

更改Redis的配置 (Changing Redis’s Configuration)

The commands outlined in this section will only alter the Redis server’s behavior for the duration of the current session, or until you run config rewrite which will make them permanent. You can alter the Redis configuration file directly by opening and editing it with your preferred text editor. For example, you can use nano to do so:

本节中概述的命令将仅在当前会话期间或直到您运行config rewrite这将使它们永久)之前更改Redis服务器的行为。 您可以通过使用首选文本编辑器打开和编辑Redis配置文件来直接更改它。 例如,您可以使用nano来这样做:

  • sudo nano /etc/redis/redis.conf

    须藤nano /etc/redis/redis.conf

Warning: The config set command is considered dangerous. By changing your Redis configuration file, it’s possible that you will cause your Redis server to behave in unexpected or undesirable ways. We recommend that you only run the config set command if you are testing out its behavior or you’re absolutely certain that you want to make changes to your Redis configuration.

警告: config set命令被认为是危险的 。 通过更改Redis配置文件,有可能导致Redis服务器以意外或不良方式运行。 我们建议您仅在测试其行为或绝对确定要更改Redis配置时运行config set命令。

It may be in your interest to rename this command to something with a lower likelihood of being run accidentally.

您可能会希望将此命令重命名为不太可能意外运行的名称。

config set allows you to reconfigure Redis at runtime without having to restart the service. It uses the following syntax:

config set允许您在运行时重新配置Redis,而无需重新启动服务。 它使用以下语法:

  • config set parameter value

    配置设置参数 值

For example, if you wanted to change the name of the database dump file Redis will produce after you run a save command, you might run a command like the following:

例如,如果要更改数据库的转储文件的名称,Redis在运行save命令后将生成的文件,则可以运行如下命令:

  • config set "dbfilename" "new_file.rdb"

    配置设置“ dbfilename”“ new_file.rdb”

If the configuration change is valid, the command will return OK. Otherwise it will return an error.

如果配置更改有效,则命令将返回OK 。 否则将返回错误。

Note: Not every parameter in the redis.conf file can be changed with a config set operation. For example, you cannot change the authentication password defined by the requirepass parameter.

注意:并非可以使用config set操作来更改redis.conf文件中的每个参数。 例如,您不能更改requirepass参数定义的身份验证密码。

永久进行配置更改 (Making Configuration Changes Permanent)

config set does not permanently alter the Redis instance’s configuration file; it only changes Redis’s behavior at runtime. To edit redis.conf after running a config-set command and make the current session’s configuration permanent, run config rewrite:

config set不会永久更改Redis实例的配置文件。 它仅在运行时更改Redis的行为。 要在运行config-set命令后编辑redis.conf并使当前会话的配置永久化,请运行config rewrite

  • config rewrite

    配置重写

This command does its best to preserve the comments and overall structure of the original redis.conf file, with only minimal changes to match the settings currently used by the server.

该命令将尽最大努力保留原始redis.conf文件的注释和整体结构,而只需进行最小的更改即可与服务器当前使用的设置相匹配。

Like config set, if the rewrite is successful config rewrite will return OK.

config set一样,如果重写成功,则config rewrite将返回OK

检查Redis的配置 (Checking Redis’s Configuration)

To read the current configuration parameters of a Redis server, run the config get command. config get takes a single argument, which can be either an exact match of a parameter used in redis.conf or a glob pattern. For example:

要读取Redis服务器的当前配置参数,请运行config get命令。 config get使用单个参数,该参数可以是redis.conf使用的参数的完全匹配,也可以是glob pattern 。 例如:

  • config get repl*

    配置获取副本*

Depending on your Redis configuration, this command might return:

根据您的Redis配置,此命令可能返回:


   
   
Output
1) "repl-ping-slave-period" 2) "10" 3) "repl-timeout" 4) "60" 5) "repl-backlog-size" 6) "1048576" 7) "repl-backlog-ttl" 8) "3600" 9) "repl-diskless-sync-delay" 10) "5" 11) "repl-disable-tcp-nodelay" 12) "no" 13) "repl-diskless-sync" 14) "no"

You can also return all of the configuration parameters supported by config set by running config get *.

您还可以通过运行config get *返回config set支持的所有配置参数。

结论 (Conclusion)

This guide details the redis-cli commands used to make changes to a Redis server’s configuration file on the fly. If there are other related commands, arguments, or procedures you’d like to see outlined in this guide, please ask or make suggestions in the comments below.

本指南详细介绍了用于快速更改Redis服务器配置文件的redis-cli命令。 如果您想在本指南中概述其他相关的命令,参数或过程,请在下面的注释中提出疑问或提出建议。

For more information on Redis commands, see our tutorial series on How to Manage a Redis Database.

有关Redis命令的更多信息,请参阅关于如何管理Redis数据库的系列教程。

翻译自: https://www.digitalocean.com/community/cheatsheets/how-to-change-redis-configuration

redis修改配置重启命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值