@ackee/kesha
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Kesha

Caching utils based on ioredis and dataloaders

Quick start 🚀

import Redis from 'ioredis';

const redisClient = new Redis({
  // Host, DB,...
})
  • Use exported utils directly
import {rateLimiter} from 'kesha';

const rateLimitedFn = rateLimiter(redisClient, (number: number) => {
  console.log('Called')
}, '', 1000)
  • Use one client
import {createRedisRepository} from 'kesha';

const repo = createRedisRepository(client)

const rateLimitedFn = rrepo.rateLimiter((number: number) => {
  console.log('Called')
}, '', 1000)
  • Provide typehints for setJSON and getJSON methods
// Per key
const repoPerKey = createRedisRepository<{ 'test:key': string }>(client)

repoPerKey.setJSON('test:key', {}) // TS Error: {} is not assignable to string

// Using template litarals to define key prefixes (From TS 4.4+)
const repo = createRedisRepository<{ [K: `test:key:${number}`]: string }>(client)

repo.setJSON('test:key:1', {}) // TS Error: {} is not assignable to string
repo.getJSON('test:key:1') // TS: Returns string
repo.getJSON('test:key:a') // TS: Returns any

Tests 🧪

  • Prepare docker container with Redis 🐳
sudo docker-compose -f docker-compose/docker-compose.yml up
  • Run the tests
npm run test

Readme

Keywords

none

Package Sidebar

Install

npm i @ackee/kesha

Weekly Downloads

3

Version

0.3.0

License

MIT

Unpacked Size

51.7 kB

Total Files

48

Last publish

Collaborators

  • pivl
  • hofp37
  • grissius
  • ackeecz
  • horaklukas
  • borecekbaji
  • davidbilik