Redis, an in-memory key-value data store comes with several commands that help us to debug and troubleshoot redis errors.
As part of our Server Management Services, we regularly help our Customers to tackle Redis related errors.
In this context, we will look into the steps to troubleshoot Redis errors.
How to troubleshoot Redis Memory related errors ?
As we discussed earlier, Redis comes up with several commands that help us to troubleshoot and debug its issues.
Many of these focus on memory management as Redis is an in-memory key-value store. Further, there are commands available to provide an overview on the status of the Redis server as well.
First command is the one that measures the current memory usage. “memory usage” tells us the amount of memory that a single key currently uses. It takes the name of a key as an argument and outputs the number of bytes it uses:
127.0.0.1:6379> memory usage key_testkey
Another one The memory malloc-stats provides an internal statistics report from jemalloc, the memory allocator used by Redis on Linux systems:
127.0.0.1:6379> memory malloc-stats
For a more general understanding of how your Redis server is using memory, we can run the memory stats command:
127.0.0.1:6379> memory stats
It outputs an array of memory-related metrics and their values. Let us now look at those metrics.
Metrics reported by memory stats
Some of the metrics reported by memory stats include:
1. peak.allocated: The peak number of bytes consumed by Redis
2. total.allocated: The total number of bytes allocated by Redis
3. startup.allocated: The initial number of bytes consumed by Redis at startup
4. replication.backlog: The size of the replication backlog, in bytes
5. clients.slaves: The total size of all replica overheads (the output and query buffers and connection contexts)
6. clients.normal: The total size of all client overheads
7. aof.buffer: The total size of the current and rewrite append-only file buffers
8. db.0: The overheads of the main and expiry dictionaries for each database in use on the server, reported in bytes
9. overhead.total: The sum of all overheads used to manage Redis’s keyspace
10. keys.count: The total number of keys stored in all the databases on the server
11. keys.bytes-per-key: The ratio of the server’s net memory usage and keys.count
12. dataset.bytes: The size of the dataset, in bytes
13. dataset.percentage: The percentage of Redis’s net memory usage taken by dataset.bytes
14. peak.percentage: The percentage of peak.allocated taken out of total.allocated
15. fragmentation: The ratio of the amount of memory currently in use divided by the physical memory Redis is actually using
Another tool available to detect memory consumption issue is the memory doctor. This feature will output any memory consumption issues that it can find and suggest potential solutions.
127.0.0.1:6379> memory doctor
Getting General Information about the Redis Instance
A debugging command that is not directly related to memory management is monitor. This command allows you to see a constant stream of every command processed by the Redis server:
1566157213.896437 [0 127.0.0.1:47740] "auth" "foobared"
1566157215.870306 [0 127.0.0.1:47740] "set" "key_1" "878"
Another command useful for debugging is info, which returns several blocks of information and statistics about the server:
os:Linux 4.15.0-52-generic x86_64
This command by default returns a lot of information. To return only info block, we can specify it as an argument to info:
127.0.0.1:6379> info CPU
Using the keys Command
The keys command is helpful in cases where we have forgotten the name of a key, or perhaps we have created one but accidentally misspelled its name. It looks for keys that match a pattern:
127.0.0.1:6379> keys pattern