0
0
RedisHow-ToBeginner · 3 min read

How to Use CONFIG Command in Redis: Syntax and Examples

Use the CONFIG command in Redis to view or change server configuration settings. It supports subcommands like GET to read settings and SET to update them dynamically without restarting the server.
📐

Syntax

The CONFIG command has three main subcommands:

  • CONFIG GET <parameter>: Retrieves the current value of a configuration parameter.
  • CONFIG SET <parameter> <value>: Changes the value of a configuration parameter immediately.
  • CONFIG RESETSTAT: Resets the server statistics counters.

Use these subcommands to manage Redis server settings dynamically.

redis
CONFIG GET <parameter>
CONFIG SET <parameter> <value>
CONFIG RESETSTAT
💻

Example

This example shows how to get the current maxmemory setting and then change it to 100mb:

redis
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "0"
127.0.0.1:6379> CONFIG SET maxmemory 104857600
OK
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "104857600"
Output
1) "maxmemory" 2) "0" OK 1) "maxmemory" 2) "104857600"
⚠️

Common Pitfalls

Common mistakes when using CONFIG include:

  • Trying to set parameters that require a server restart (these changes won't persist).
  • Using incorrect parameter names or values, which causes errors.
  • Not checking the current value before changing it, which can lead to unexpected behavior.

Always verify the parameter name and understand if the change is temporary or permanent.

redis
127.0.0.1:6379> CONFIG SET maxclients abc
(error) ERR value is not an integer or out of range

# Correct usage:
127.0.0.1:6379> CONFIG SET maxclients 1000
OK
Output
(error) ERR value is not an integer or out of range OK
📊

Quick Reference

SubcommandDescription
CONFIG GET Get the value of a configuration parameter
CONFIG SET Set a configuration parameter dynamically
CONFIG RESETSTATReset server statistics counters

Key Takeaways

Use CONFIG GET to read current Redis configuration values.
Use CONFIG SET to change configuration parameters without restarting Redis.
Not all parameters can be changed dynamically; some require a server restart.
Always verify parameter names and valid values to avoid errors.
CONFIG RESETSTAT clears server stats counters for fresh monitoring.