0.9.0 • Published 9 years ago

dq v0.9.0

Weekly downloads
64
License
MIT
Repository
github
Last release
9 years ago

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

0.9.0

9 years ago

0.8.0

9 years ago

0.7.0

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.0

11 years ago

0.1.1-f

11 years ago

0.1.1-e

11 years ago

0.1.1-c

11 years ago

0.1.1-b

11 years ago

0.1.1-a

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.1g

12 years ago

0.1.1f

12 years ago

0.1.1e

12 years ago

0.1.1c

12 years ago

0.1.1b

12 years ago

0.1.1a

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago