Configuration Commands in Redis

1. Changing the Port:

To change the default port from 6379 to 6380, locate the port directive in the configuration file and set its value:

port 6380

2. Setting a Password:

If you want to require clients to authenticate with a password, uncomment and modify the “requirepass” directive:

requirepass your_password

3. Configuring Persistence (RDB Snapshot):

To configure periodic RDB snapshots, you can set the following options:

save 900 1 # Save after 900 seconds if at least 1 key changed

save 300 10 # Save after 300 seconds if at least 10 keys changed

save 60 10000 # Save after 60 seconds if at least 10000 keys changed

4. Enabling AOF Persistence:

To enable AOF (Append-Only File) persistence, uncomment the appendonly directive and set it to yes:

appendonly yes

5. Setting AOF Rewrite Rules:

To control AOF rewrite behavior, you can set options like auto-aof-rewrite-percentage and auto-aof-rewrite-min-size:

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

6. Limiting Memory Usage (Max Memory):

To limit Redis memory usage, you can set maxmemory:

maxmemory 1gb

7. Configuring Replication:

If you want Redis to act as a master in replication, specify the replication options:

replicaof <master_ip> <master_port>

masterauth <master_password>

8. Tuning for Performance:

There are various options you can adjust for better performance. For example, increasing the number of allowed client connections:

maxclients 10000

Remember that these are just examples of commonly used configuration options. Depending on your specific use case, you might need to explore other options in the redis.conf file.

Note: After making changes to the configuration file, you’ll need to restart the Redis server for the changes to take effect. Always ensure that you backup the original configuration file before making changes and follow best practices to secure your Redis deployment, especially when using authentication and exposing Redis to the internet.

Complete Tutorial of Configuration in Redis

Redis configuration involves setting various options and parameters that govern the behavior of the Redis server. Configuration settings impact aspects such as networking, memory usage, persistence, security, and more. The Redis configuration file, usually named redis.conf, is where these settings are defined. Redis provides a wide range of configuration options that allow you to tailor the server to your specific needs.

Important topics for Configuration in Redis

  • Syntax for configuring Redis:
  • Configuration Commands in Redis:
  • How to pass arguments via the command line?
  • How to change Redis configuration while the server is running?
  • How to Configure Redis as a cache?

Similar Reads

Syntax for configuring Redis:

...

Configuration Commands in Redis:

The syntax for configuring Redis involves modifying the redis.conf file. Each configuration option is specified in the form of a keyword followed by its value....

How to pass arguments via the command line?

1. Changing the Port:...

How to change Redis configuration while the server is running?

Redis allows you to override configuration settings using command-line arguments when starting the Redis server. This can be particularly useful when you want to modify specific settings without modifying the entire configuration file. Here’s how to do it:...

How to Configure Redis as a cache?

Changing Redis configuration while the server is running involves using the CONFIG SET command. This command allows you to modify various configuration options on the fly without requiring a server restart. Here’s how you can change Redis configuration while the server is running:...

Contact Us