https://github.com/bustle/redis-loader
A Redis command batcher
https://github.com/bustle/redis-loader
Last synced: 9 months ago
JSON representation
A Redis command batcher
- Host: GitHub
- URL: https://github.com/bustle/redis-loader
- Owner: bustle
- License: mit
- Created: 2018-03-29T02:05:37.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T18:21:07.000Z (over 3 years ago)
- Last Synced: 2025-04-02T17:11:12.017Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 916 KB
- Stars: 6
- Watchers: 11
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RedisLoader
An [`ioredis`](https://github.com/luin/ioredis)-like object that batches commands via [`dataloader`](https://github.com/facebook/dataloader). Under the hood we have `dataloader` utilize redis's `multi` transactions and [pipelining](https://redis.io/topics/pipelining) to group commands called. We also support batching in streams.
### Installation
```
npm i --save @bustle/redis-loader
or
yarn add @bustle/redis-loader
```
### Examples
```js
// RedisLoader supports an optional logger function with stats on each batch of commands
function logger (stats) {
//...
}
// set up like you would `ioredis`
const redis = redisLoader('redis://localhost:6379/1', { keyPrefix: 'foo', logger })
// or setup ioredis
const redis = new Redis(redisUrl, redisOptions)
const redisLoader = new RedisLoader({ redis, logger })
// three commands sent to Redis together in one multi
await Promise.all([
redis.ping(),
redis.dbsize(),
redis.time()
])
// three commands sent separately to redis
await redis.ping()
await redis.dbsize()
await redis.time()
```