{"id":46133,"library":"redis-metrics","title":"redis-metrics","description":"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.","status":"active","version":"1.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/getconversio/redis-metrics","tags":["javascript","redis","metrics","counter","trend"],"install":[{"cmd":"npm install redis-metrics","lang":"bash","label":"npm"},{"cmd":"yarn add redis-metrics","lang":"bash","label":"yarn"},{"cmd":"pnpm add redis-metrics","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for Redis client operations","package":"redis","optional":false},{"reason":"Used for date/time manipulation in time-aware counters","package":"moment","optional":true}],"imports":[{"note":"Package uses CommonJS by default, but ES modules are supported via bundlers. The default export is the constructor.","wrong":"var RedisMetrics = require('redis-metrics');","symbol":"default","correct":"import RedisMetrics from 'redis-metrics';"},{"note":"Named import is incorrect; the package exports a single constructor function as default.","wrong":"import { RedisMetrics } from 'redis-metrics';","symbol":"RedisMetrics","correct":"import RedisMetrics from 'redis-metrics';"},{"note":"Counter is not exported directly; instantiate via RedisMetrics instance.","wrong":"import { Counter } from 'redis-metrics';","symbol":"Counter","correct":"const metrics = new RedisMetrics(); const counter = metrics.counter('name');"}],"quickstart":{"code":"import RedisMetrics from 'redis-metrics';\n\nconst metrics = new RedisMetrics();\nmetrics.client.on('error', err => console.error('Redis error:', err));\n\nconst counter = metrics.counter('pageview');\ncounter.incr();\ncounter.incr();\ncounter.incr();\n\ncounter.count().then(cnt => {\n  console.log(cnt); // 3\n}).catch(err => console.error(err));","lang":"javascript","description":"Shows how to instantiate RedisMetrics, create a counter, increment it, and retrieve the count using promises."},"warnings":[{"fix":"Ensure redis-server is running and accessible via default host/port, or provide custom Redis options to the constructor.","message":"The package requires a running Redis server; no embedded Redis or default configuration.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always attach an 'error' listener to metrics.client: metrics.client.on('error', (err) => { /* handle */ })","message":"Error handling on the Redis client is critical; unhandled errors can crash the process.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use .then() and .catch() instead of callbacks for future-proof code.","message":"Counter methods ('incr', 'count') return Promises; callbacks are deprecated in newer versions but still work.","severity":"gotcha","affected_versions":">=1.4.0"},{"fix":"Replace { timeGranularity: 'hour' } with { granularity: 'hour' }.","message":"The 'timeGranularity' option in counter() is deprecated; use 'granularity' instead.","severity":"deprecated","affected_versions":">=1.4.2"}],"env_vars":null,"search_vec":"'aggreg':17,56 'api':60 'back':6 'built':55 'callback':36 'configur':24 'counter':7,22,50,64 'day':27 'differenti':46 'easi':16 'generic':48 'getconversio':42 'granular':25 'hour':26 'javascript':61 'last':43 'librari':11 'logic':57 'maintain':40 'metric':3,63 'month':29 'namespac':33 'node.js':13 'offer':52 'pattern':39 'pre':54 'pre-built':53 'promis':38 'provid':15 'redi':2,5,32,49,62 'redis-back':4 'redis-metr':1 'releas':44 'seri':21 'simpl':59 'stabl':45 'support':34 'time':20 'time-seri':19 'track':10 'trend':9,65 'v1.4.2':14 'week':28 'year':30","created_at":"2026-06-07T12:58:27.563214+00:00","updated_at":"2026-06-07T12:58:27.563214+00:00","problems":[{"fix":"Use a single Redis instance or use a library with cluster support.","cause":"Redis cluster mode is not supported; client may be trying to connect to a cluster node.","error":"Error: ReplyError: MOVED ..."},{"fix":"Instantiate: const metrics = new RedisMetrics(); then metrics.counter('name')","cause":"Importing the package incorrectly, e.g., const RedisMetrics = require('redis-metrics'); but using RedisMetrics.counter instead of new RedisMetrics().counter","error":"TypeError: metrics.counter is not a function"},{"fix":"Ensure Redis is running and metrics.client.on('error') is set to log connection issues.","cause":"Counter not created successfully due to missing or invalid Redis connection.","error":"UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'incr' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/getconversio/redis-metrics#readme","github":"https://github.com/getconversio/redis-metrics","docs":null,"changelog":null,"pypi":null,"npm":"redis-metrics","openapi_spec":null,"status_page":null,"smithery":null,"categories":["analytics","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}