Socket
Socket
Sign inDemoInstall

redis-streams

Package Overview
Dependencies
16
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redis-streams

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


Version published
Weekly downloads
406
decreased by-19.12%
Maintainers
2
Install size
715 kB
Created
Weekly downloads
 

Readme

Source

redis-streams

NPM Version NPM Downloads Build Status Test Coverage

Extends the official node_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 and redis-wstream by @jeffbski.

Installation

npm install redis-streams

Usage

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

This will extend the RedisClient prototype with two additional functions:

readStream(key) - get a Readable stream from redis.

writeStream(key, maxAge) - get a Writable stream from redis.

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

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 for additional usage examples.

Caching Proxy

You could also implement a Connect caching proxy middleware.

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 module utilizes redis-streams for this purpose, but in a more advanced way.

Keywords

FAQs

Last updated on 11 May 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc