Socket
Book a DemoInstallSign in
Socket

@ackee/kesha

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ackee/kesha

Caching utils based on ioredis and dataloaders

latest
Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
98
-2.97%
Maintainers
0
Weekly downloads
 
Created
Source

Kesha

Caching utils based on ioredis and dataloaders

Quick start 🚀

  • Initialize ioredis client
import Redis from 'ioredis';

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

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

const repo = createRedisRepository(client)

const rateLimitedFn = repo.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

Keywords

cache

FAQs

Package last updated on 17 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts