Skip to main content

CONFIG REWRITE

Syntax​

CONFIG REWRITE

Time complexity: O(N) where N is the number of lines in the configuration file.

ACL categories: @admin, @dangerous, @slow

The CONFIG REWRITE command writes the current configuration to the file that Dragonfly was started with, so that changes made with CONFIG SET survive a restart.

Unlike Valkey, which rewrites a valkey.conf file, Dragonfly rewrites the flag file passed with --flagfile, which holds one --name=value flag per line. The config_file field of INFO server shows the path of that file.

CONFIG REWRITE writes every parameter listed by CONFIG GET whose current value differs from its default, whether the value was changed with CONFIG SET, passed on the command line, or read from the file. If --maxmemory was not set, this includes the maxmemory limit that Dragonfly computed at startup. After a restart, Dragonfly uses that written value instead of computing the limit again. Other flags, such as --proactor_threads, are not written. Values are written in plain text, including passwords such as requirepass.

The file is updated as follows:

  • An existing --name=value line of a written parameter is updated in place. Comments, blank lines, and the lines of other flags stay as they are.
  • Parameters that have no line yet are added at the end of the file, below a # Generated by CONFIG REWRITE line. Everything below that line is replaced on each rewrite, so do not add your own settings there.
  • A parameter that was set back to its default value is not written.

Dragonfly writes the new content to a temporary file in the same directory and then renames it over the original file. The command returns an error in these cases:

  • ERR The server is running without a config file: Dragonfly was started without --flagfile.
  • ERR Cannot read config file: the file can't be opened, for example because it was removed after startup, or because --flagfile lists several comma-separated files.
  • ERR Failed to create temporary file: the Dragonfly process can't create files in the directory of the configuration file.
  • ERR Failed to write config file: writing to the temporary file failed.
  • ERR Failed to rewrite config file: the file can't be replaced. This happens when the file itself is bind-mounted into a container; mount the directory that contains it instead.

Return​

Simple string reply: OK when the configuration file was rewritten, error otherwise.

Examples​

Without a configuration file:

dragonfly> CONFIG REWRITE
(error) ERR The server is running without a config file

With Dragonfly started with --flagfile=/etc/dragonfly/dragonfly.conf:

$ cat /etc/dragonfly/dragonfly.conf
# Dragonfly configuration
--maxclients=100
--dbfilename=mydump
$ redis-cli CONFIG SET maxclients 200
OK
$ redis-cli CONFIG SET timeout 60
OK
$ redis-cli CONFIG REWRITE
OK
$ cat /etc/dragonfly/dragonfly.conf
# Dragonfly configuration
--maxclients=200
--dbfilename=mydump

# Generated by CONFIG REWRITE
--maxmemory=25.58GiB
--timeout=60

The --maxmemory line holds the limit that Dragonfly computed at startup, so its value depends on the machine. The order of the generated lines can vary.