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

redback

v0.5.1

Published

A high-level Redis library

Downloads

1,552

Readme

Redback

NPM version Build Status Downloads

A high-level Redis library.

$ npm install redback

Introduction

Redback provides an accessible and extensible interface to the Redis data types and allows you to create your own structures with ease. Redback comes with the following built-in structures: List, Set, SortedSet, Hash, Channel, Cache

It also comes with the following advanced data structures:

  • DensitySet - A sorted set where adding an element increments its score and removing it decrements it
  • KeyPair - Uses two hash structures and an auto-incrementing key to assign an ID to each unique value
  • SocialGraph - Similar to Twitter's (following vs. followers)
  • CappedList - A list with a fixed length
  • Queue - A simple FIFO or LIFO queue
  • RateLimit - Count the number of times an event occurs over an interval. See this introduction.
  • BloomFilter - A probabilistic structure used to test whether an an element exists in a set

Usage

var redback = require('redback').createClient();

// or

var redis = require('redis').createClient();
var redback = require('redback').use(redis);
var user3 = redback.createSocialGraph(3);
user3.follow(1, callback);

var log = redback.createCappedList('log', 1000);
log.push('Log message ...');

var user = redback.createHash('user1');
user.set({username: 'chris', password: 'foobar'}, callback);

Creating your own structures

Use addStructure(name, methods) to create your own structure.

Let's create a queue that can be either FIFO or LIFO:

redback.addStructure('SimpleQueue', {
    init: function (options) {
        options = options || {};
        this.fifo = options.fifo;
    },
    add: function (value, callback) {
        this.client.lpush(this.key, value, callback);
    },
    next: function (callback) {
        var method = this.fifo ? 'rpop' : 'lpop';
        this.client[method](this.key, callback);
    }
});

Call createSimpleQueue(key, options) to use the queue:

var queue = redback.createSimpleQueue('my_queue', {fifo: true});
queue.add('awesome!');

Structures have access to a Redis key this.key and the Redis client this.client. If an init() method is defined then it is called after the structure is instantiated. Also note that init() receives any extra parameters from create<structure>().

Other uses

Cache backend

var cache = redback.createCache(namespace);
cache.set('foo', 'bar', callback);
cache.get('foo', function (err, foo) {
    console.log(foo); //bar
});

Pub/sub provider

var channel = redback.createChannel('chat').subscribe();

//To received messages
channel.on('message', function (msg) {
   console.log(msg);
});

//To send messages
channel.publish(msg);

Documentation

See the annotated source.

Tests

The tests require a local redis instance running on localhost:6379. Note that redis database #11 will be flushed prior to each run.

$ npm test

Credits

  • Matt Ranney for his node_redis library.
  • GitHub user sreeix for the bloom filter implementation.

License

MIT