Git Product home page Git Product logo

node-dq's Introduction

Node.js - dq

dq is a simple priority queue built on Redis.

Install

npm install --save dq

Usage

connect(config, [callback])

alias: create()

  1. config: Can take any of the following: a. name (required) b. port, defaults to 6379 c. host, defaults '127.0.0.1' d. password
  2. callback: optional, has signature (err, q)

Example:

var dq = require('dq')

var q = dq.connect({name: 'tasks'})

// or...

dq.connect({name: 'tasks'}, function (err, q) {

})

count(callback)

  • callback: has signature (err, count)

Example:

var dq = require('dq')

var q = dq.connect({name: 'tasks'})
q.count(function (err, count) {
  console.log(count) // => 1356
})

deq([count], callback)

  • callback: has signature (err, val)

val is an Array if count was specified.

Example:

var dq = require('dq')

var q = dq.connect({name: 'tasks'})
q.deq(function (err, val) {
  console.log(val)
})

enq(value, [priority], callback)

  • value: (required) data to put in the queue, should be a string, any non-string will be type coerced
  • priority: (optional), defaults to 0, you should choose between 0 and 1 using the result of Math.random(). Values between -Infinity and Infinfity will be accepted.
  • callback: has signature (err, val)

Example:

var dq = require('dq')

var q = dq.connect({name: 'tasks'})
q.enq('some data', Math.random(), function (err) { })

peak(start, count, [callback])

Return data from start until start + count, but don't remove the data.

example:

Assume the queue has the following contents: ['a', 'b', 'c', 'd']

var dq = require('dq')

dq.create({name: 'somedata'}, function (err, q) {
  q.peak(1, 2, function (err, data) {
    console.dir(data) // => ['b', 'c']
  })
})

License

Licensed under MIT. See LICENSE for more details.

Copyright (c) 2012-2015 JP Richardson

node-dq's People

Contributors

jprichardson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.