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

redmoon

v1.0.2

Published

Asynchronous broker for multi-source data collection.

Downloads

4

Readme

redmoon

version download

Asynchronous broker for multi-source data collection using redis.

If redmoon.load is called, and it returned to find the data in the cache, if cache data does not exist, call the specified function(subscriber) to subscribe.

js-standard-style

Usage


// setting
var redmoon = require('redmoon').create(config)

// event handle
redmoon
	.on('timeout', function(keyword) {
		console.error('redmoon timeout', keyword)
	})
	.on('error', function(err) {
		console.error('redmoon error', err)
	});

// express
app.get('/search/:key/:page/:limit?', function (req, res) {
  redmoon.load(function (err, items, meta) {
    res.json({
      meta: meta,
      items: items
    })
  }, req.params.key, req.params.page, req.params.limit)
})

// collector
// The first event is no meta data in moon.
redmoon
	.subscribe(subscriber)
	.garbage.start(3600)	// It deletes the data collected before to 60 minutes.

var subscriber = function (moon) {
	redmoon.atomic(moon.uuid, function(cb) {
		process(cb, moon)
	}, function(err, data) {
		complete(moon, data)
	})
}

var process = function (cb, moon) {
	// call cb when complete load data
	cb(err, {
		meta: {},
		items: {}
	})
}

var complete = function(moon, data) {
	redmoon.add(function(err) {
		redmoon.trigger(moon.topic)
	}, moon, data.meta, data.items)
}


// moon
// {
// 	uuid: uuid,
// 	key: key,
// 	topic: topic,
// 	meta: meta	// if first event then it is undefined
// }

Methods

redmoon.connect(config)

Connect redis.

redmoon.events()

Initialize redmoon events.

  • error
  • ready
  • connect
  • end

redmoon.load(cb(err, items, meta), key, page, limit)

Load collected data. If not exist data then trigger event for collection.

redmoon.loadMeta(cb(err, metas), uuid, count)

Load meta data.

redmoon.add(cb, moon, meta, items)

Add collected data to cache.

redmoon.subscribe(cb(err, moon))

Set callback function for the collection event.

redmoon.unsubscribe(cb())

Unset callback function for the collection event.

redmoon.trigger(topic, data)

Trigger event for the specified topic.

redmoon.atomic(uuid, process(cb), complete(err, data))

The function to prevent the duplication proccess.

If it has available resources, given process calls and then release the resources used by cb call in process. After the release, and it executes the transfer of data in proccess to complete.

redmoon.end()

Close the connection to the redis server.

redmoon.truncate(unix)

Deleting cache data collected before a specified time.

redmmon.toTopic(uuid)

It converts uuid to the topic.

redmoon.garbage.start(offset)

Start garbage collection. Deleting cache data collected before a offset time.

redmoon.garbage.stop()

Stop garbage collection.

Redmoon.uuid(key)

Make unique string.

Redmmon.uuid()

Return unixtimestamp.

Redmoon.create(config)

Create Redmoon instance with config.

Release History

See the changelog

LICENSE

redmoon is licensed under the MIT license.