Redis INFO Output Parser
redis-info is a focused JavaScript utility designed to accurately parse the raw string output of the Redis `INFO` command into a structured JavaScript object. This library provides a programmatic way to access detailed Redis server statistics, configuration parameters, and operational metrics. The current stable version, 3.1.0, was published approximately 4-5 years ago, indicating a maintenance-oriented release cadence primarily driven by critical bug fixes or significant changes to the Redis `INFO` command's format itself. Its primary differentiation lies in its single-purpose design, offering a direct and unopinionated conversion of the `INFO` string without coupling to a full Redis client library.
Common errors
-
TypeError: (0 , redis_info_1.parse) is not a function
cause Attempting to import the CommonJS `redis-info` package using incorrect ES Module syntax like `import { parse } from 'redis-info';`.fixUse CommonJS `require` syntax: `const { parse } = require('redis-info');`. -
Output from `redis-info.parse()` is missing expected fields or shows incorrect values for recent Redis versions.
cause The `redis INFO` command output format evolves with new Redis server versions. `redis-info` v3.1.0 might not be updated to handle fields introduced in newer Redis server versions (e.g., Redis 6.x, 7.x, 8.x) or correctly interpret changed field structures.fixVerify the Redis server version and compare its `INFO` output with the `redis-info` parser's behavior. Manually inspect the raw `INFO` string and the parsed object. Consider reporting an issue to the library maintainer or implementing a custom parser for missing fields if using a very recent Redis version.
Warnings
- gotcha Redis `INFO` command output varies significantly across different Redis server versions (e.g., Redis 2.x, 3.x, 4.x, 5.x, 6.x, 7.x, 8.x). The `redis-info` parser (v3.1.0, published 4-5 years ago) may not fully or correctly parse `INFO` output from newer Redis versions, leading to missing or incorrectly interpreted fields.
- gotcha The `redis-info` package, especially version 3.1.0, is built as a CommonJS module. Direct ES Module `import` syntax might not work as expected without a transpilation step or specific Node.js configuration, leading to `TypeError` or `SyntaxError`.
Install
-
npm install redis-info -
yarn add redis-info -
pnpm add redis-info
Imports
- parse
import { parse } from 'redis-info';const { parse } = require('redis-info');
Quickstart
const { parse } = require('redis-info');
const redisInfoString = `
# Server
redis_version:2.4.10
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d
redis_mode:standalone
os:Linux 5.15.0-78-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:9.4.0
process_id:1234
process_supervised:no
run_id:54321deadbeef0987654321deadbeef098765
tcp_port:6379
server_time_usec:1678886400000000
uptime_in_seconds:3600
uptime_in_days:0
hz:10
lru_clock:123456789
executable:/usr/local/bin/redis-server
config_file:/etc/redis/redis.conf
# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0
# Memory
used_memory:1048576
used_memory_human:1.00M
used_memory_rss:2097152
used_memory_rss_human:2.00M
used_memory_peak:1048576
used_memory_peak_human:1.00M
`;
const info = parse(redisInfoString);
console.log('Redis Version:', info.redis_version);
console.log('OS:', info.os);
console.log('Connected Clients:', info.connected_clients);
console.log('Memory Used Human:', info.used_memory_human);
// Example of accessing a non-existent property (returns undefined)
console.log('Replication Role (may not exist in old Redis versions):', info.role);