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

fucq

v0.4.1

Published

Fixed-capacity FIFO queue that enforces uniqueness among elements, using Redis.

Downloads

4

Readme

#FIFO Uniqueness Circular Queue

(acronym intended)

Fixed-capacity FIFO queue that enforces uniqueness among elements, using Redis.

Every operation requires only one I/O to and from Redis, minimizing I/O overhead.

  • Adding N items takes O(N) time.
  • Fetching all N items in queue takes O(1) time with Redis, but O(N) time because of deserialization.
  • Everything else is O(1).

##Install

npm install fucq

##Example

Check out the following example written in ES6. Hopefully you're familiar with coroutines/generators/Bluebird! :)

var QUEUE_CAPACITY = 3;

var fucq = require('fucq');
var assert = require('assert');
var Bluebird = require('bluebird');

var q = fucq.create({
    client: redisClient, // required
    key: 'foo:1', // required - Redis key name
    capacity: QUEUE_CAPACITY, // required
    inactivityExpire: 10, // optional - in seconds - if not set, the keys never expire
    serialize: function (numericResult) { // optional
        // If not set, a default serializer is used (which is basically a JSON.stringify()
        // that can handle undefined). Redis can only store strings, so everything needs
        // to be converted to and from a string.
        return String(numericResult);
    }
    deserialize: function (stringStored) { // optional - similar to serialize
        // If not set, a default deserializer is used (which is basically a JSON.parse()
        // that can handle undefined)
        return Number(stringStored);
    }
});
q = Bluebird.promisifyAll(q);

assert.strictEqual(q.capacity, QUEUE_CAPACITY); // property .capacity - not asynchronous

Bluebird.coroutine(function* () {
    yield q.emptyAsync(); // method .empty() - clears out all relevant Redis keys
    
    yield q.addAsync(1); // method .add() - queue is now [1]
    assert.strictEqual(res, q.OK); // status OK
    
    yield q.addAsync(2, 3); // queue is now [3, 2, 1]
    assert.strictEqual(res, q.OK);
    
    yield q.addAsync(3); // duplicates cannot be added
    assert.strictEqual(res, q.DUP_ENTRY); // status DUP_ENTRY
    
    yield q.addAsync(4); //  queue is now [4, 3, 2]
    assert.strictEqual(res, q.OK);

    console.log(yield q.allAsync()); // method .all()
    // prints [4, 3, 2]
    // instead of ['4', '3', '2']
    // which a plain ol' Redis call would return without a deserializer
    
    assert.strictEqual(yield q.sizeAsync(), QUEUE_CAPACITY); // method .size() - asynchronous
})();

##Test

Test is written in ES6, so 6to5-node is being used for transpilation.

npm install -g 6to5
npm install
npm test