# redis-streams

> Extends the node redis client with readStream, writeStream, and writeThrough functions.

Latest version **1.1.0** (published 2016-05-11) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2016-05-11 |
| First published | 2015-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | David Von Lehman |
| Maintainers | aerobatic, dvonlehman |
| Keywords | redis, streams, pipe, cache |

## Links

- npm: https://www.npmjs.com/package/redis-streams
- Repository: https://github.com/4front/redis-streams
- Homepage: https://github.com/4front/redis-streams#readme
- Issues: https://github.com/4front/redis-streams/issues
- npm.io page: https://npm.io/package/redis-streams

## Dependencies (4)

- [redis](https://npm.io/package/redis.md) ^2.6.0-2
- [through2](https://npm.io/package/through2.md) ^2.0.1
- [redis-rstream](https://npm.io/package/redis-rstream.md) ^0.1.2
- [redis-wstream](https://npm.io/package/redis-wstream.md) ^0.2.5

## 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.1.0 (latest) — 2016-05-11
- 1.0.6 — 2015-04-13
- 1.0.5 — 2015-03-11
- 1.0.4 — 2015-03-04
- 1.0.3 — 2015-02-26
- 1.0.2 — 2015-02-26
- 1.0.1 — 2015-02-25
- 1.0.0 — 2015-02-25

## README

# redis-streams

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]

Extends the official [node_redis](https://www.npmjs.com/package/redis) client with additional functionality to support streaming data into and out of Redis avoiding buffering the entire contents in memory. The real work is powered by the [redis-rstream](https://www.npmjs.com/package/redis-rstream) and [redis-wstream](https://www.npmjs.com/package/redis-wstream) by [@jeffbski](https://github.com/jeffbski).

## Installation
```
npm install redis-streams
```

## Usage

```js
var redis = require('redis');
require('redis-streams')(redis);
```

This will extend the `RedisClient` prototype with two additional functions:

__`readStream(key)`__  - get a [Readable stream](http://nodejs.org/api/stream.html#stream_class_stream_readable) from redis.

__`writeStream(key, maxAge)`__ - get a [Writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable) from redis.

__`writeThrough(key, maxAge)`__  - write to redis and pass the stream through.

```js
var redis = require('redis');
require('redis-streams')(redis);

var redisClient = redis.createClient();

redisClient.readStream(key)
	.pipe(process.stdout);

fs.createReadStream('file.txt')
	.pipe(redisClient.writeStream(key, maxAge))
	.on('finish', done);

fs.createReadStream('file.txt')
	.pipe(redisClient.writeThrough(key, maxAge))
	.pipe(process.stdout);
```
See the [unit tests](https://github.com/4front/redis-streams/blob/master/test/redis.js) for additional usage examples.


#### Caching Proxy
You could also implement a Connect caching proxy middleware.

```js
var redis = require('redis');
var request = require('request');
require('redis-streams')(redis);

var redisClient = redis.createClient();

app.get('/cache/:key', function(req, res, next) {
	redis.exists(req.params.key, function(err, exists) {
	   if (err) return next(err);

		if (exists)
			return redis.readStream(req.params.key).pipe(res);

		// Cache the remote http call for 60 seconds
		request.get('http://somewhere.com/' + req.params.key)
			.pipe(redis.writeThrough(req.params.key, 60))
			.pipe(res);
	});
});
```

The [express-api-proxy](https://github.com/4front/express-api-proxy) module utilizes `redis-streams` for this purpose, but in a more advanced way.

[npm-image]: https://img.shields.io/npm/v/redis-streams.svg?style=flat
[npm-url]: https://npmjs.org/package/redis-streams
[travis-image]: https://img.shields.io/travis/4front/redis-streams.svg?style=flat
[travis-url]: https://travis-ci.org/4front/redis-streams
[coveralls-image]: https://img.shields.io/coveralls/4front/redis-streams.svg?style=flat
[coveralls-url]: https://coveralls.io/r/4front/redis-streams?branch=master
[downloads-image]: https://img.shields.io/npm/dm/redis-streams.svg?style=flat
[downloads-url]: https://npmjs.org/package/redis-streams

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