npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-list-stream

v1.0.0

Published

a simple redis list stream

Downloads

2

Readme

redis-list-stream

CircleCI Codacy Badge

Build Status

Redis supports implementation of a message queue using FIFO lists This is a trivial implementation of a such a message queue but with the addtion of a stream based interface.

Messages in Redis are persisted in a list. Messages are writen using rpush ,push data at the end of the list, while reads are implemented using blpop, blocked pop from the head of list. Streams is a natural programming abastraction for respective write and read functions.

For writes the assumption is that the application will trust REDIS to persist the message, in a fire and forget kind mode.

const {RedisWriteableStream} = require('redis-list-stream');

stream = RedisWriteableStream.createInterface({
	redis: {
		host: process.env.REDIS_HOST || 'localhost',
		port: process.env.REDIS_PORT || 8120
	},
	queueName : 'myQueue'
});

stream.write(JSON.stringify({
	test: 1,
	date: new Date()
}));

stream.end();

stream.on('finish',()=>{
	process.exit(0);
});

RedisWritableStream.createInterface()

Create an instrance of RedisWritableStream

  • RedisWritableStream.createInterface(options)

options object properties

| Property | Description | | ----------|-------------| |redis | contains normal redis parameters for creating a connection, for more see redis documentation | |queueName | name of the queue / list created in Redis. A new list will be created if it does not exists otherwise will use the existing one | |client | a redis connection to be used by this class. Ideally this connection shouldn't be shared with other redis transactions |

At the moment the write implementation is rather inneficient as it does not 'batch' the writes, but that is for something for the very near future.

In addition the current implementation does not offer any mechanism for alerting the calling program of success or failure of the underlying rpush. Again this is somehting that will be addressed very soon.

For reads the implentation is equally simple

const {RedisReadableStream} = require('redis-list-stream');

stream = RedisReadableStream.createInterface({
	redis: {
		host: process.env.REDIS_HOST || 'localhost',
		port: process.env.REDIS_PORT || 8120
	},
	queueName : 'myQueue'
});

stream.on('data',(data)=>{
	console.log(data.toString());
});

The library will pop one message at a time from from the queue and generate the data event. Another way to is implement a Tanform stream responsible of implementing the actions a process has to do when receives an message . The example below does exactly the same as the previous example.

const {RedisReadableStream} = require('redis-list-stream');
const {Transform} = require('stream');

class TestTranform extends Transform {
	constructor(params) {
		super(params);
	}
	_transform(chunk,encoding, cb) {
		console.log(chunk.toString());
		cb();
	}
}
const tStream = new TestTranform();

stream = RedisReadableStream.createInterface({
	redis: {
		host: process.env.REDIS_HOST || 'localhost',
		port: process.env.REDIS_PORT || 8120
	},
	queueName : 'myQueue'
});

stream.pipe(tStream);

RedisWritableStream.createInterface()

Create an instrance of RedisWritableStream

  • RedisWritableStream.createInterface(options)

options object properties

| Property | Description | | ----------|-------------| |redis | contains normal redis parameters for creating a connection, for more see redis documentation | |queueName | name of the queue / list created in Redis. A new list will be created if it does not exists otherwise will use the existing one | |client | a redis connection to be used by this class. Ideally this connection shouldn't be shared with other redis transactions |