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

news/2024/7/3 4:44:57

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修改配置重启命令


http://www.niftyadmin.cn/n/3649567.html

相关文章

SSH连接工具FinalShell的安装与使用

常见的SSH连接工具有好多,我以前常用的是xshellxftp组合。虽然需要付费,但是免费版已经基本满足我的需求。关于xshell和xftp的安装和使用可以参考我以前的博客:Xftp和Xshelll的安装—远程连接linux FinalShell是一体化的的服务器,网络管理软件…

[j2me]利用kSOAP让MIDP设备与WebService之间传递类对象

[j2me]利用kSOAP让MIDP设备与WebService之间传递类对象编写者日期关键词郑昀ultrapower2005-8-14J2me webservice soa ksoap serialization MIDP CLDC中国移动GPRS网络的连接方式有两种类型,一种是WAP+GPRS,接入名称叫CMWAP,一种是…

盖茨比乔布斯_盖茨比中的自定义字体

盖茨比乔布斯Choosing the right font can add great value to a site and enhance the user experience. The right font-loading strategy, however, can be somewhat of a challenge. That’s why Gatsby provides several developer-friendly solutions for all of our fon…

Android中GridView使用

GridView(网格视图)是按照行列的方式来显示内容的,一般用于显示图片,图片等内容,比如实现九宫格图,用GridView是首选,也是最简单的。主要用于设置Adapter。 GridView常用的XML属性: 属性名称 描述 an…

旧版Chrome浏览器的安装和使用——chrome63

虽然新版的Chrome浏览器很好用,但是界面风格我还是喜欢旧版的浏览器。我的电脑上有新版和旧版两个。不过正常情况下谷歌浏览器只能安装一个。我的做法是新版的浏览器正常安装,旧版的有点类似eclipse,解压就可以使用。不过使用前面需要解决一个…

javascript 引擎_V8引擎和JavaScript优化技巧

javascript 引擎V8 is Google’s engine for compiling our JavaScript. Firefox has it’s own engine called SpiderMonkey, it’s quite similar to V8 but there are differences. We will be discussing the V8 engine in this article. V8是Google用来编译JavaScript的引…

Widget的基本知识与历史渊源

一、Widget是什么? App Widget是应用程序窗口小部件(Widget)是微型的应用程序视图,它可以被嵌入到其它应用程序中(比如桌面)并接收周期性的更新。你可以通过一个App Widget Provider来发布一个Widget。…

华为云青年开发班:黑白棋游戏开发

放假回家第一天,继续肝!写一篇博客证明我还在! 实验成果 任何时候都不要放弃自己的梦想,也许下一刻,梦想就会成真了呢!