0
0
RedisHow-ToBeginner · 3 min read

How to Configure Redis: Simple Steps and Examples

To configure Redis, edit the redis.conf file or pass options directly when starting the server with redis-server. Key settings include port, bind, and requirepass for security and network control.
📐

Syntax

The main way to configure Redis is by editing the redis.conf file or by passing command-line options when starting Redis with redis-server.

  • redis.conf: Text file with key-value settings.
  • redis-server [options]: Start Redis with inline configuration.
  • Common options include port (default 6379), bind (IP addresses to listen on), and requirepass (password protection).
plaintext
# Example redis.conf snippet
port 6379
bind 127.0.0.1
requirepass yourpassword
💻

Example

This example shows how to start Redis with a custom port and password using command-line options, and how to connect using the password.

bash
# Start Redis on port 6380 with password
redis-server --port 6380 --requirepass mysecret

# Connect using redis-cli with password
redis-cli -p 6380
127.0.0.1:6380> AUTH mysecret
OK
127.0.0.1:6380> PING
PONG
Output
OK PONG
⚠️

Common Pitfalls

Common mistakes when configuring Redis include:

  • Not setting requirepass, leaving Redis open without password.
  • Binding Redis to 0.0.0.0 without firewall, exposing it publicly.
  • Forgetting to restart Redis after changing redis.conf.
  • Using incorrect syntax in redis.conf causing Redis to fail on start.
plaintext
# Wrong: No password and open to all IPs
port 6379
bind 0.0.0.0

# Right: Bind to localhost and set password
port 6379
bind 127.0.0.1
requirepass strongpassword
📊

Quick Reference

SettingDescriptionExample
portPort Redis listens onport 6379
bindIP addresses Redis listens onbind 127.0.0.1
requirepassPassword for client authenticationrequirepass mypassword
maxmemoryLimit memory usagemaxmemory 256mb
appendonlyEnable data persistenceappendonly yes

Key Takeaways

Configure Redis by editing redis.conf or using command-line options with redis-server.
Always set requirepass to secure your Redis instance.
Bind Redis to localhost or trusted IPs to avoid exposing it publicly.
Restart Redis after changing configuration for changes to take effect.
Use maxmemory and persistence settings to control resource use and data safety.