Registry / analytics / redis-tracker

redis-tracker

JSON →
library1.1.9jsnpmunverified

A TypeScript-first library for tracking RPC call counts and other action metrics using Redis time-bucketed counters. Version 1.1.9 is the current stable release with no breaking changes reported. It provides four main exports: `statis` for connection setup (standalone, cluster, or passing an existing ioredis instance), `trackAction` for incrementing counters, `searchKeys` for scanning Redis keys by pattern, and `statRedis` for reading counter values. Key differentiators include automatic time-bucket expiry (seconds to years), support for both module-specific and global counter namespaces, and native TypeScript definitions.

npm install redis-tracker
INSTALL
IMPORT
SIG · REDIS-TRACKER
R
redis-tracker
analyticsjavascriptv1.1.9
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.

statis
✓ import { statis } from 'redis-tracker'
✗ const { statis } = require('redis-tracker')
The package is ESM-only; CommonJS require() will fail. Always use an ESM import.
trackAction
✓ import { trackAction } from 'redis-tracker'
✗ import trackAction from 'redis-tracker'
trackAction is a named export, not the default export. Using a default import returns undefined.
searchKeys
✓ import { searchKeys } from 'redis-tracker'
✗ import { searchKeys } from 'redis-tracker/types'
searchKeys is exported from the package root, not a subpath. No types subpath exists.

Shows connection setup with standalone Redis, tracking an action, and retrieving counts using searchKeys and statRedis.

import { statis, trackAction, searchKeys, statRedis } from 'redis-tracker'; statis.redis.standalone({ host: process.env.REDIS_HOST ?? '127.0.0.1', port: Number(process.env.REDIS_PORT) || 6379, password: process.env.REDIS_PASSWORD || '', }); // Track an action trackAction({ prefix: 'qa', module_name: 'swap-tx-rpc', }); // Search keys and retrieve counts async function getCounts() { const keys = await searchKeys('qa:swap-tx-rpc:*'); const results = await Promise.all( keys.map(async (key) => ({ key, value: Number((await statRedis.get(key)) || 0), })) ); console.log(results); } getCounts().catch(console.error);
Debug
Known issues
deprecatedThe package does not have any deprecated APIs. Always use the latest version.
fix
Upgrade to latest version: npm install redis-tracker@latest
affects: <1.0.0
gotchatrackAction does not return anything; it's fire-and-forget. Do not await or expect a result.
fix
Call trackAction without await; use a separate mechanism for error handling if needed.
affects: >=1.0.0
gotchasearchKeys uses Redis SCAN, which may return empty array or incomplete results under heavy write load.
fix
Implement retry logic, or use a dedicated aggregation store if exact counts are required.
affects: >=1.0.0
gotchastatRedis.get returns a string or null; you must convert to Number for numeric operations.
fix
Wrap with Number() and handle null: Number((await statRedis.get(key)) || 0)
affects: >=1.0.0
Errors
Common errors & fixes
ERR wrong number of arguments for 'get' command
Using statRedis.get() with wrong context (e.g., not initialized properly).
fix
Ensure you called statis.redis.standalone() or .cluster() before using statRedis.
TypeError: statis.redis.standalone is not a function
Importing statis incorrectly, or using a very old version that doesn't have .redis.
fix
Use ESM import: import { statis } from 'redis-tracker'; and upgrade to latest version.
Error: Module not found: Can't resolve 'redis-tracker'
Package not installed, or bundler config missing resolution for ESM.
fix
Install: npm install redis-tracker. Ensure your project supports ESM (e.g., "type": "module" in package.json).
Redis connection refused
Redis server not running or wrong host/port.
fix
Start Redis server or check REDIS_HOST/REDIS_PORT environment variables.
Upgrade
Version history
1.1.9latest on npm
Audit
Dependencies
ioredisrequiredRequired as a peer dependency for Redis connection. The library uses ioredis under the hood and expects it to be installed.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
redis-tracker — npm install redis-tracker · libregistry