Registry / database / alien-node-redis-utils

alien-node-redis-utils

JSON →
library1.4.6jsnpmunverified

Helper functions for Redis cache on NodeJS. Version 1.4.6. The functions are pure and curried with Ramda. Provides caching utilities like getItem, setItem, deleteItem, and query cache helpers (maybeAddToQueryCache, pluckFromQueryCache, setOrDeleteCacheBucket). Designed for Node.js with Redis client. Differentiates by using Ramda for functional programming style.

npm install alien-node-redis-utils
INSTALL
IMPORT
SIG · ALIEN-NODE-REDIS-U
A
alien-node-redis-utils
databasejavascriptv1.4.6
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
const cacheUtils = require('alien-node-redis-utils')(redisClient);
const cacheUtils = require('alien-node-redis-utils');
The package exports a function that must be called with a Redis client instance.
getItem
const cacheUtils = require('alien-node-redis-utils')(redisClient); cacheUtils.getItem('key');
const { getItem } = require('alien-node-redis-utils')(redisClient);
Methods are not directly exported; use the returned object.
setItem
const cacheUtils = require('alien-node-redis-utils')(redisClient); cacheUtils.setItem('key', expire, data);
const cacheUtils = require('alien-node-redis-utils'); cacheUtils.setItem('key', expire, data);
Must initialize with redisClient first.

Shows how to initialize the library with a Redis client, set an item with TTL, then retrieve it.

const redis = require('redis'); const redisClient = redis.createClient(); const cacheUtils = require('alien-node-redis-utils')(redisClient); const cacheKey = 'myKey'; const expire = 3600; const data = { hello: 'world' }; cacheUtils.setItem(cacheKey, expire, data) .then(() => cacheUtils.getItem(cacheKey)) .then(result => console.log(result)) .catch(err => console.error(err));
Debug
Known issues
gotchaThe package exports a function, not an object. You must call it with a Redis client instance to get the methods.
fix
Use require('alien-node-redis-utils')(redisClient).
affects: >=1.0.0
gotchagetItem rejects with an error if key is not found. No distinction between error and missing key.
fix
Catch error to handle missing keys.
affects: >=1.0.0
gotchasetItem expects expire in seconds, not milliseconds. Using milliseconds will set a very long TTL.
fix
Convert milliseconds to seconds: Math.floor(ms / 1000).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cacheUtils.getItem is not a function
Forgetting to call the exported function with redisClient.
fix
const cacheUtils = require('alien-node-redis-utils')(redisClient);
ReplyError: ERR value is not an integer or out of range
Passing milliseconds as expire instead of seconds.
fix
Ensure expire is in seconds (e.g., 3600 for 1 hour).
Upgrade
Version history
1.4.6latest on npm
Audit
Dependencies
ramdarequiredUsed for currying and functional utilities
redisrequiredPeer dependency for Redis client
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources