Redis - Server
Redis - Server Management
Section titled “Redis - Server Management”Redis server commands are used to manage, monitor, and configure the Redis instance itself. They are essential tools for administrators and developers to ensure the health, performance, and stability of the server.
Monitoring with the INFO command
Section titled “Monitoring with the INFO command”The INFO command provides a comprehensive report on the server’s state. You can request all information or specify a section (e.g., INFO memory, INFO clients). Below is an example output from a modern Redis 7.x server.
127.0.0.1:6379> INFO# Serverredis_version:7.0.5redis_git_sha1:00000000redis_git_dirty:0redis_build_id:e753424d9c44569eredis_mode:standaloneos:Linux 5.15.0-52-generic x86_64arch_bits:64...# Clientsconnected_clients:1client_recent_max_input_buffer:2client_recent_max_output_buffer:0blocked_clients:0...# Memoryused_memory:996568used_memory_human:973.21Kused_memory_rss:4087808used_memory_rss_human:3.90M...# Persistencerdb_changes_since_last_save:0rdb_bgsave_in_progress:0rdb_last_save_time:1668541334...aof_enabled:1aof_rewrite_in_progress:0...# Replicationrole:masterconnected_slaves:0...# Keyspacedb0:keys=10,expires=2,avg_ttl=3599988Essential Server Commands
Section titled “Essential Server Commands”The following table lists critical server commands, grouped by function.
General Management
Section titled “General Management”| Command | Description |
|---|---|
| INFO [section] | Provides detailed information and statistics about the server. |
| CONFIG GET | Gets the value of a configuration parameter (e.g., CONFIG GET port). |
| CONFIG SET | Sets a configuration parameter on-the-fly without a server restart. |
| TIME | Returns the current server time as a UNIX timestamp and microseconds. |
| SHUTDOWN [NOSAVE|SAVE] | Shuts down the server. Can optionally prevent or force a final save to disk. |
Database & Key Management
Section titled “Database & Key Management”| Command | Description |
|---|---|
| FLUSHDB | Removes all keys from the currently selected database. Use with caution. |
| FLUSHALL | Removes all keys from all databases. Extremely destructive; use with extreme caution. |
| DBSIZE | Returns the total number of keys in the selected database. |
Replication
Section titled “Replication”| Command | Description |
|---|---|
| REPLICAOF | Makes the server a replica of another instance. This is the modern replacement for SLAVEOF. |
| REPLICAOF no one | Promotes a replica to a master. |
| ROLE | Returns the role of the instance (master, replica, or sentinel) and replication status. |
| SLAVEOF | Deprecated since Redis 5. Use REPLICAOF instead. |
Diagnostics & Monitoring
Section titled “Diagnostics & Monitoring”| Command | Description |
|---|---|
| MONITOR | Streams all commands processed by the server in real-time. Excellent for debugging. |
| SLOWLOG GET [count] | Shows the Redis slow queries log, helping identify performance bottlenecks. |
| CLIENT LIST | Gets the list of client connections to the server. |
| LASTSAVE | Returns the UNIX timestamp of the last successful RDB save. |
Beyond a Single Server: Modern Architectures
Section titled “Beyond a Single Server: Modern Architectures”While these commands help manage a single Redis server, modern applications often require high availability and horizontal scaling. For these needs, Redis offers advanced solutions:
• Redis Sentinel: A separate system that provides high availability for Redis. It monitors master and replica instances and can automatically perform a failover if the master becomes unavailable. • Redis Cluster: Provides a way to run a Redis installation where data is automatically sharded across multiple nodes. This allows for horizontal scaling of both data storage and throughput.