TypeScript Redis utility toolkit for caching and Pub/Sub. Lightweight, fast, and easy to use.
- Cache management with
getOrSetCache
andclearCache
- Pub/Sub helpers with
publish
andsubscribe
- Built with TypeScript for type safety
- Uses official
redis
v4 client
npm install redikit
import client from 'redikit/connection';
// client is a connected RedisClientType instance
import { getOrSetCache, clearCache } from 'redikit/cache';
async function fetchData() {
const data = await getOrSetCache('my-key', async () => {
// fetch fresh data from DB or API
return { foo: 'bar' };
}, 3600);
console.log(data);
}
async function clearMyCache() {
await clearCache('my-key');
}
import { publish, subscribe } from 'redikit/pubsub';
await subscribe('my-channel', (message) => {
console.log('Received message:', message);
});
await publish('my-channel', { hello: 'world' });
-
npm run build
— compile TypeScript to JavaScript -
npm run dev
— run with ts-node in development -
npm run lint
— lint source files with ESLint -
npm start
— run compiled code
To build the package:
npm run build
Output files will be in the dist
folder, including type declarations (.d.ts
).
Make sure you:
- Increment the version in
package.json
. - Run
npm run build
. - Run
npm publish
.
- Redis connection URL is configured with environment variable
REDIS_URL
. - Default fallback:
redis://localhost:6379
.
MIT License © Nurul Islam Rimon
GitHub - nurulislamrimon/redikit
redis, cache, pubsub, typescript, redis-utils, node-redis