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

storage-pod

v1.0.0

Published

Store data in Redis, get back the key it was stored at

Downloads

7

Readme

Storage Pod build status

Store data in Redis, get back the key it was stored at. The purpose of the library is to transport chunks of data between multiple processes. It will store your data in Redis and provide you with the key it used to store it. You can then send the key to the other process (for example via pub/sub or a queue) and it can then receive the package. That's all.

Installation

Install it in your project via:

npm install storage-pod --save

Usage

First, you create a storage function. For that you need a namespace you want to use for the generated keys (in our example that is mynamespace) and a Redis client (which needs to be API compatible with the redis NPM package).

var client = require('redis').createClient();
var createStorage = require('storage-pod');
var store = createStorage('mynamespace', client);

Now you have a store function, which you can use to store data. You provide it with a callback which will receive an error if something went wrong and the key that your data is accessible with:

store(JSON.stringify({ hello: 'world' }), function(storeErr, key) {
  // now you can use your key for whatever
});

You can now send the key to the other process. It will just need to GET the key from Redis.

Serialize

As you want to serialize the value most of the time, you can provide a serialize function to the createStorage function as an option. The serialize function is applied to your data before it is stored in Redis. In the following example we use JSON as our serialization format, but you can choose whatever you want (MsgPack, ProtoBuf, transit... Just provide a function that takes data and returns it serialized).

var store = createStorage('mynamespace', client, {
  serialize: JSON.stringify
});

// Now you can just provide an object:
store({ hello: 'world' }, function(storeErr, key) {
});

Set a TTL

This library is meant to be used to send a piece of data to another process. What happens after the other library has read the data? It is now useless and can be deleted. You can either delete it when you have read it or you could set a TTL on it. If you want to go with the second option, you can do it like this (we set the time in milliseconds):

var store = createStorage('mynamespace', client, {
  ttl: 200 // The TTL for each stored value is now 200ms
});

Contributing

First install all development dependencies with npm install. Then run npm run ci to see if the code:

  • Passes the test suite (aka. npm test)
  • Passes the linter (aka. npm run jshint)
  • Passes the code style checker (aka. npm run jscs)

This will also automatically happen before every commit and be checked by Travis CI. Tests are written using tape.

#lesscode

This library is inspired by the #lesscode movement: It has a very specific purpose, only one runtime dependency (a Redis client, which you need to provide to it and is therefore not a runtime dependency of the package) and just a few lines of code.

Thanks to soveran for the inspiration (especially OST).

License

This code is published under the MIT license.