Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
A simple and fast redis based queue, supports both fifo and lifo.
npm i shape-of-q
const q = require('shape-of-q')('myqueue')
q.on('error', console.log)
// push a new message
q.push('hello')
q.pull({ polling: true }, (msg, done) => {
console.log(msg)
done()
})
Async await is supported as well!
q.pull({ polling: true }, async msg => {
console.log(msg)
})
Create a new queue, the queue name parameter is mandatory.
Options:
const q = require('shape-of-q')('myqueue', {
encoding: 'json', // default: null
type: 'lifo', // default: 'fifo'
client: Object, // custom redis client
host: '127.0.0.1' // redis host for the internal client,
encoder: msgpack.encode, // default null
decoder: msgpack.decode, // default null
binaryData: true // default false
})
shape-of-q
is an event emitter and you should listen for the error
event.
If you are working with objects and want to speed up the serialization you can use the encoder
and decoder
option, both of them must be sync functions.
If the encoder
produces binary data make sure to pass { binaryData: true }
as option.
push
Add a new message to the queue.
If the encoding has been set to 'json'
you can pass plain objects.
q.push('hello')
pull
Retrieve a single message from the queue.
To enable polling, pass { polling: true }
as option and pollingInterval
if you want to customize the interval (must be expressed in seconds).
The api supports both classic callbacks and async await.
// callbacks
q.pull({ polling: true }, (msg, done) => {
console.log(msg)
done()
})
// async-await
q.pull({ polling: true }, async msg => {
console.log(msg)
})
If you pass an error to done
or return an error in the async version the message will be put back in the queue.
list
Get all elements in the queue.
q.list((err, msg) => {
console.log(msg)
})
stop
Stops the polling and closes the connection to redis.
q.stop()
flush
Flushes a queue removing all its elements.
q.flush((err) => {
if (err) console.log(err)
})
MIT
Copyright © 2018 Tomas Della Vedova
FAQs
A simple and fast redis based queue
The npm package shape-of-q receives a total of 8 weekly downloads. As such, shape-of-q popularity was classified as not popular.
We found that shape-of-q demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.