Registry / database / redis-flagger

redis-flagger

JSON →
library0.1.4jsnpmunverified

A lightweight library for content flagging backed by Redis, with optional time-window support. Current stable version is 0.1.4. It allows flagging, unflagging, and checking if an element has been flagged, using Redis as the backend. Keys are built by JSON-encoding and SHA1-hashing the element, with configurable key prefix and TTL. Differentiators include simple API, support for any data type (objects, arrays, strings), and the ability to use an existing Redis connection or create a new one. Best suited for preventing duplicate processing, filtering streams, or as a distributed semaphore.

npm install redis-flagger
INSTALL
IMPORT
SIG · REDIS-FLAGGER
R
redis-flagger
databasejavascriptv0.1.4
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.

flagger
import flagger from 'redis-flagger';
const { flagger } = require('redis-flagger');
The package exports a single object via module.exports, so default import or require works.
DEFAULT
import flagger, { DEFAULT } from 'redis-flagger';
const DEFAULT = require('redis-flagger').DEFAULT;
DEFAULT is a named export containing default constants like KEY_BUILDER.
setup
flagger.setup({ host: '127.0.0.1' });
setup is a method on the default export, not a standalone export.

Shows how to import, setup, flag, check, and unflag an element with custom TTL.

import flagger from 'redis-flagger'; // Setup with new Redis connection flagger.setup({ host: process.env.REDIS_HOST ?? '127.0.0.1', port: parseInt(process.env.REDIS_PORT ?? '6379') }); const element = { foo: 'bar' }; // Flag element with default TTL (60 seconds) flagger.flag(element); // Check if flagged (returns promise) flagger.flagged(element).then(console.log); // true // Flag with custom TTL (120 seconds) flagger.flag(element, 120); // Unflag flagger.unflag(element); flagger.flagged(element).then(console.log); // false
Debug
Known issues
gotchaObject order matters: flagging and checking with objects that have same key-value pairs but different order will result in different hashed keys.
fix
Ensure consistent object ordering (e.g., using JSON.stringify with sorted keys) or use string representations.
affects: >=0.0.0
gotchaDefault TTL is 60 seconds if not specified in setup or flag call.
fix
Set ttl in setup options or pass TTL as second argument to flag().
affects: >=0.0.0
deprecatedThe library may rely on an older version of the 'redis' package which uses createClient differently. Check compatibility with newer Redis clients.
fix
Use the same Redis client version as tested, or consider wrapping with ioredis.
affects: <=0.1.4
Errors
Common errors & fixes
TypeError: flagger.setup is not a function
Incorrect import: using named import { flagger } instead of default import.
fix
Use 'import flagger from 'redis-flagger';' instead of 'import { flagger } from 'redis-flagger';'.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or host/port are incorrect.
fix
Start Redis server or specify correct host and port in setup().
TypeError: flagger.flagged(...).then is not a function
Forgot that flagged() returns a Promise and did not await it.
fix
Use await flagger.flagged(element) or .then() to get the boolean result.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
redisrequiredRequired for connecting to Redis. The library wraps the 'redis' package (usually ioredis or node-redis, but source suggests ioredis-like usage).
Agent activity
9 hits · last 30 days
node
6
Meta
1
Amazon
1
Resources
redis-flagger — npm install redis-flagger · libregistry