You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

redis-streams

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-streams

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

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
1.5K
20.6%
Maintainers
2
Weekly downloads
 
Created
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

redis

FAQs

Package last updated on 11 May 2016

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