Registry / analytics / redis-metrics

redis-metrics

JSON →
library1.4.2jsnpmunverified

Redis-backed counter and trend tracking library for Node.js (v1.4.2). Provides easy aggregation of time-series counters with configurable granularity (hour, day, week, month, year) and Redis namespacing. Supports both callback and Promise patterns. Maintained by GetConversio, last release stable. Differentiates from generic Redis counters by offering pre-built aggregation logic and simple API.

npm install redis-metrics
INSTALL
IMPORT
SIG · REDIS-METRICS
R
redis-metrics
analyticsjavascriptv1.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import RedisMetrics from 'redis-metrics';
var RedisMetrics = require('redis-metrics');
Package uses CommonJS by default, but ES modules are supported via bundlers. The default export is the constructor.
RedisMetrics
import RedisMetrics from 'redis-metrics';
import { RedisMetrics } from 'redis-metrics';
Named import is incorrect; the package exports a single constructor function as default.
Counter
const metrics = new RedisMetrics(); const counter = metrics.counter('name');
import { Counter } from 'redis-metrics';
Counter is not exported directly; instantiate via RedisMetrics instance.

Shows how to instantiate RedisMetrics, create a counter, increment it, and retrieve the count using promises.

import RedisMetrics from 'redis-metrics'; const metrics = new RedisMetrics(); metrics.client.on('error', err => console.error('Redis error:', err)); const counter = metrics.counter('pageview'); counter.incr(); counter.incr(); counter.incr(); counter.count().then(cnt => { console.log(cnt); // 3 }).catch(err => console.error(err));
Debug
Known issues
gotchaThe package requires a running Redis server; no embedded Redis or default configuration.
fix
Ensure redis-server is running and accessible via default host/port, or provide custom Redis options to the constructor.
affects: >=0.0.0
gotchaError handling on the Redis client is critical; unhandled errors can crash the process.
fix
Always attach an 'error' listener to metrics.client: metrics.client.on('error', (err) => { /* handle */ })
affects: >=0.0.0
gotchaCounter methods ('incr', 'count') return Promises; callbacks are deprecated in newer versions but still work.
fix
Use .then() and .catch() instead of callbacks for future-proof code.
affects: >=1.4.0
deprecatedThe 'timeGranularity' option in counter() is deprecated; use 'granularity' instead.
fix
Replace { timeGranularity: 'hour' } with { granularity: 'hour' }.
affects: >=1.4.2
Errors
Common errors & fixes
Error: ReplyError: MOVED ...
Redis cluster mode is not supported; client may be trying to connect to a cluster node.
fix
Use a single Redis instance or use a library with cluster support.
TypeError: metrics.counter is not a function
Importing the package incorrectly, e.g., const RedisMetrics = require('redis-metrics'); but using RedisMetrics.counter instead of new RedisMetrics().counter
fix
Instantiate: const metrics = new RedisMetrics(); then metrics.counter('name')
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'incr' of undefined
Counter not created successfully due to missing or invalid Redis connection.
fix
Ensure Redis is running and metrics.client.on('error') is set to log connection issues.
Upgrade
Version history
1.4.2latest on npm
Audit
Dependencies
redisrequiredCore dependency for Redis client operations
momentoptionalUsed for date/time manipulation in time-aware counters
Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
redis-metrics — npm install redis-metrics · libregistry