# redis-rstream

> redis-rstream - node.js redis read stream which streams binary or utf8 data in chunks from a redis key using an existing redis client (streams2)

Latest version **1.0.1** (published 2018-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install redis-rstream
pnpm add redis-rstream
yarn add redis-rstream
bun add redis-rstream
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-06-14 |
| First published | 2012-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 0 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Jeff Barczewski |
| Maintainers | jeffbski |
| Keywords | stream, streams2, read, redis, binary |

## Links

- npm: https://www.npmjs.com/package/redis-rstream
- Repository: https://github.com/jeffbski/redis-rstream
- Homepage: https://github.com/jeffbski/redis-rstream#readme
- Issues: http://github.com/jeffbski/redis-rstream/issues
- npm.io page: https://npm.io/package/redis-rstream

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-06-14
- 1.0.0 — 2018-06-14
- 0.1.3 — 2017-04-18
- 0.1.2 — 2013-08-06
- 0.1.1 — 2013-07-09
- 0.1.0 — 2013-04-12
- 0.0.7 — 2012-11-26

## README

# redis-rstream

redis-rstream is a node.js redis read stream which streams binary or utf8 data in chunks from a redis key using an existing redis client. (streams2) Tested with mranney/node_redis client.

[![Build Status](https://secure.travis-ci.org/jeffbski/redis-rstream.png?branch=master)](http://travis-ci.org/jeffbski/redis-rstream)

## Installation

```bash
npm install redis-rstream
```

You will also need the `redis` client (`npm install redis`) or other compatible library. You an also optionally install `hiredis` along with `redis` for additional performance.

## Usage

 - `redisRStream(client, key, [options])` - Construct a read stream instance by passing in `client`, redis `key`, and options. Be sure to enable an option in your redis client to return Buffers for the data, like `detect_buffers: true` so that binary data will be read properly. The default `options.chunkSize` (the size of the data packets in the stream) is 64KB, this is ignored if using the streams2 read(chunkSize) since the provided chunkSize will be used instead. You can limit how many pending reads are allowed for this read stream, by specifying `options.maxPendingReads` which defaults to 2. You also have the option to specify a range with `options.startOffset` (inclusive) and `options.endOffset` (non-inclusive), streaming only the chosen segment.

```javascript
var redis = require('redis');
var redisRStream = require('redis-rstream'); // factory
var client = redis.createClient(null, null, {detect_buffers: true}); // create client using your options and auth
redisRStream(client, 'keyToStreamFrom')  // create instance of read stream w/default 64KB chunk size
  .pipe(...)
```

Tested with mranney/node_redis client, but should work with any client that implements:

 - `getrange(key, start, stop, cb)` - where key is a Buffer and the data returned is a Buffer


## Goals

 - Simple read stream which can use existing redis client (and especially mranney/node_redis)
 - Remove all the complexity of managing a stream and reading in chunks from a redis key
 - Create normal pausable node.js read stream which can be piped or used as any other stream
 - uses streams2 from node 0.10+.

## Why

mranney/node_redis does not have direct ability to read a key as a stream, so rather than writing this logic again and again, wrap this up into a read stream so we simply point it to a key and it streams.

Other redis stream implementations use their own direct network connections to redis, but I would prefer to use an existing connection for all my redis work which makes authentication and things lke failover easier to deal with.

## Get involved

If you have input or ideas or would like to get involved, you may:

 - contact me via twitter @jeffbski  - <http://twitter.com/jeffbski>
 - open an issue on github to begin a discussion - <https://github.com/jeffbski/redis-rstream/issues>
 - fork the repo and send a pull request (ideally with tests) - <https://github.com/jeffbski/redis-rstream>

## License

 - [MIT license](http://github.com/jeffbski/redis-rstream/raw/master/LICENSE)

---
_Source: https://npm.io/package/redis-rstream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
