redikit
v1.0.2
Published
TypeScript version of lightweight Redis utility functions for caching and pub/sub
Maintainers
Readme
RediKit
TypeScript Redis utility toolkit for caching and Pub/Sub. Lightweight, fast, and easy to use.
Features
- Cache management with
getOrSetCacheandclearCache - Pub/Sub helpers with
publishandsubscribe - Built with TypeScript for type safety
- Uses official
redisv4 client
Installation
npm install redikitUsage
Connection Setup
import client from 'redikit/connection';
// client is a connected RedisClientType instanceCache Utilities
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');
}Pub/Sub Utilities
import { publish, subscribe } from 'redikit/pubsub';
await subscribe('my-channel', (message) => {
console.log('Received message:', message);
});
await publish('my-channel', { hello: 'world' });Scripts
npm run build— compile TypeScript to JavaScriptnpm run dev— run with ts-node in developmentnpm run lint— lint source files with ESLintnpm start— run compiled code
Build
To build the package:
npm run buildOutput files will be in the dist folder, including type declarations (.d.ts).
Publishing
Make sure you:
- Increment the version in
package.json. - Run
npm run build. - Run
npm publish.
Configuration
- Redis connection URL is configured with environment variable
REDIS_URL. - Default fallback:
redis://localhost:6379.
License
MIT License © Nurul Islam Rimon
Repository
GitHub - nurulislamrimon/redikit
Keywords
redis, cache, pubsub, typescript, redis-utils, node-redis
