Redis is a prevalent in-memory data store that provides high performance and low latency for applications. Its advanced data structures and programmability make it a leading choice for caching, real-time analytics, and other use cases that require fast and efficient data processing.
In the following article, we share a detailed guide on how to monitor Redis effectively. We start by introducing Redis and some of its alternatives, after which we share a list of important performance metrics and discuss how to monitor them using different commands and tools.
Redis is an open-source, in-memory, data structure store that also offers optional persistence. Because Redis stores data in memory, it is inherently faster than traditional, disk-based databases. Additionally, Redis's replication and clustering capabilities enable developers to build distributed systems that can handle high traffic and large data volumes.
It’s called a “data structure” store because it natively supports several data structures, including strings, sets, lists, hashes, bitmaps, geospatial indexes, and sorted sets. This enables developers to store and process a wide range of data types in Redis.
For example, developers can use sorted sets to work with data that requires sorting or ranking, such as leaderboards or rate limiters. They can use the same Redis instance to also store location coordinates, using the geospatial data type.
Like traditional database systems, Redis supports transactions, which allow users to execute multiple commands in one step. Developers can also perform server-side scripting using Lua, or write stored procedures using the Redis Functions API.
Redis is often deployed as a distributed application cache, but can also be used as a standalone database. Another common use case for Redis is as a messaging system for real-time applications. Its publish/subscribe implementation is packed with useful features, like pattern-matching subscriptions and sharding. The Redis stream data type can be used to power data streaming and messaging use cases at scale.
While searching for an in-memory data store, you may find yourself comparing Redis with alternatives, like Memcached, Aerospike, Elasticsearch, and MongoDB. Each data store has its own unique features and capabilities, which make them well suited for different use cases.
Redis and Memcached are both key-value stores that are optimized for caching. In terms of read/write speed and memory usage, both offer similar performance and efficiency. However, Redis comes with configurable persistence, whereas Memcached doesn’t.
Redis also supports a wider range of data structures, which makes it more flexible than Memcached, and offers more features, such as persistence, transactions and atomicity, pipelining, pub-sub, Lua scripting, and clustering.
Aerospike is an in-memory, NoSQL database optimized for high data volumes. Like Redis, it offers a rich set of features, including server-side scripting, elastic scaling, optional persistence, and multi-cloud support. Both technologies deliver similar levels of performance, availability, atomicity, and resilience.
While Redis supports a wider range of data structures than Aerospike, the latter offers more flexibility with regards to replication and access control. In addition, client library support for Aerospike is limited when compared to Redis.
Elasticsearch is a full-text search engine that is optimized for fast and efficient search queries. While Redis, Aerospike, and Memcached are primarily used for caching, Elasticsearch is designed for searching and analyzing data.
Elasticsearch's advanced search capabilities and support for structured and unstructured data make it an ideal choice for use cases like analytics, fuzzy searching, and document processing. With that said, if desired, you can also utilize Elasticsearch as a cache for your primary storage. Just remember that since it’s not optimized for caching by default, you will have to manually tune the cluster for better indexing and concurrency.
Even though MongoDB is primarily a traditional, disk-based database, it also offers an in-memory engine for faster read and write operations. This in-memory engine is optimized to query large volumes of data in real time.
Both MongoDB and Redis provide high-level concurrency, transactions, and flexible deployment architectures. However, compared to Redis, the support for data structures and advanced caching features in MongoDB is limited.
In short, there is no outright winner when comparing Redis, Aerospike, Memcached, Elasticsearch, and MongoDB. The one you end up choosing will depend on your personalized business needs and developer preferences.
Redis exposes several metrics related to its status, performance, availability, and replication. Administrators can use these metrics to monitor health, predict malfunctions, resolve bottlenecks, and identify avenues for improvement.
Monitoring metrics related to individual nodes and the overall cluster is important in ensuring that Redis is performing as expected. You can use the GET /v1/nodes/stats endpoint of the Redis REST API to obtain the following real-time statistics of a node:
To obtain the same statistics (as above) at the cluster level, all you need to do is modify the endpoint to GET /v1/cluster/stats.
Database metrics paint a clear picture of how well a Redis instance is dealing with data. The GET /v1/bdbs/stats endpoint of the Redis API returns the following key statistics in its response:
To view metrics specific to sharding, you can use the GET /v1/shards/stats endpoint. Some of the metrics it returns are:
The Redis INFO command outputs the following list of memory-related statistics that can be key in detecting issues and optimizing throughput.
The output of the Redis INFO command contains several metrics related to replication. Some of the most important metrics are:
If the instance is a replica, some additional fields are returned, including:
The LATENCY group of commands can be used to perform latency monitoring of a Redis cluster. The LATENCY LATEST command outputs the most recently logged latency event. The output includes the name of the event, the timestamp at which the latest spike happened, the latest latency (in milliseconds), and the all-time highest latency for the event.
The LATENCY HISTORY command displays the latency time series for an event. It comes in handy when you want to analyze an event’s historical latency trends. If you want to reset the time series for an event, you can use the LATENCY RESET command.
If you want to visualize the trends of a latency event, the LATENCY GRAPH command is the one to use. It returns an ASCII-art style graph. Lastly, if you want a detailed, human-readable analysis of latency issues and potential solutions, you can issue the LATENCY DOCTOR command.
The Redis admin console is a web-based application that shows metrics related to the cluster, nodes, databases, shards, replication, and memory. To log into the admin console you must retrieve the login credentials stored in a Kubernetes Secret, and forward the local port to the port of the UI service (default port is 8443). After that, you can view the console by visiting https://www.site24x7.com.
The admin console is a great place to get a holistic overview of a Redis instance. It displays information related to connections, CPU usage, incoming and outgoing traffic, disk space, RAM, latency, memory limit, and more. It also shows several database-specific metrics, such as evicted objects/second, hit ratio, command latency, RAM fragmentation, and total keys.
The MONITOR command in Redis provides a continuous stream of all commands that are being executed by the Redis server. It can act as a powerful debugging tool by allowing users to observe and understand what’s happening to a live Redis server.
For example, if you are debugging an application, you may enter MONITOR to see which commands the application is executing on Redis. Or if you are experiencing an exceptionally high request rate, you can use the MONITOR command to see the nature of the incoming requests.
You can issue the MONITOR command via the Redis CLI or telnet. Use Ctrl+C to stop a MONITOR stream started via the CLI. To close a telnet stream, you have to enter the RESET or QUIT commands. MONITOR doesn’t log administrative commands and redacts sensitive data. It’s important to note that continuously streaming MONITOR on a production instance can impact performance.
Site24x7's monitoring plugin provides great insight into the health, performance, and availability of a Redis cluster. The plugin includes a web-based dashboard that lets you visualize important metrics as graphs and charts.
For example, you can monitor used and peak used memory, CPU utilization in system and user modes, key-space hits and misses, rejected connections, connected slaves, connected clients, and more. The Python-based plugin can be downloaded directly from GitHub, and installed in a few simple steps.
Redis is a popular in-memory data store that excels in performance, resilience, scalability, and durability. Its easy-to-use query interface, support for multiple data structures, built-in replication and clustering features, and data persistence make it a staple of several distributed IT infrastructures. Whether you are building for the cloud or on-premise, you can use Redis for caching, session management, or real-time data streaming.
Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.
Apply Now