CONFIG

Introduction and Use Case(s)

The CONFIG command in Redis is used to manage the server configuration at runtime without the need to restart the server. It allows administrators to view, set, and rewrite configuration parameters. Typical use cases include changing settings for logging, memory limits, or adjusting behavior during maintenance.

Syntax

  1. CONFIG GET <parameter>
  2. CONFIG SET <parameter> <value>
  3. CONFIG RESETSTAT
  4. CONFIG REWRITE

Parameter Explanations

  • <parameter>: The name of the configuration parameter you want to get or set. For example, loglevel, maxmemory.
  • <value>: The new value for the configuration parameter.

Return Values

  • CONFIG GET <parameter>: Returns a list of keys and their current values.

    Example:

    1. dragonfly> CONFIG GET loglevel
    2. 1) "loglevel"
    3. 2) "notice"
  • CONFIG SET <parameter> <value>: Returns OK if the configuration change was successful.

    Example:

    1. dragonfly> CONFIG SET loglevel verbose
    2. OK
  • CONFIG RESETSTAT: Resets the statistics reported by Redis.

    Example:

    1. dragonfly> CONFIG RESETSTAT
    2. OK
  • CONFIG REWRITE: Rewrites the configuration file with the current configuration.

    Example:

    1. dragonfly> CONFIG REWRITE
    2. OK

Code Examples

  1. dragonfly> CONFIG GET maxmemory
  2. 1) "maxmemory"
  3. 2) "0"
  4. dragonfly> CONFIG SET maxmemory 104857600
  5. OK
  6. dragonfly> CONFIG GET maxmemory
  7. 1) "maxmemory"
  8. 2) "104857600"
  9. dragonfly> CONFIG RESETSTAT
  10. OK
  11. dragonfly> CONFIG REWRITE
  12. OK

Best Practices

  • Use CONFIG SET cautiously as it can affect the stability and performance of your Redis instance.
  • Always back up your current configuration before making changes.
  • Apply changes during maintenance windows if possible to avoid impacting live traffic.

Common Mistakes

  • Setting inappropriate values that exceed the server’s physical resources leading to crashes or slowdowns.
  • Forgetting to perform CONFIG REWRITE after setting new configurations which results in the loss of changes after a restart.

FAQs

What happens if I don’t use CONFIG REWRITE after CONFIG SET?

Without CONFIG REWRITE, the changes made using CONFIG SET are not saved to the configuration file and will be lost upon server restart.

Can all configuration parameters be changed using CONFIG SET?

No, some parameters are read-only at runtime and cannot be changed using CONFIG SET.