Skip to content

Commit

Permalink
Use node-uuid instead of redis id coounters.
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Feb 21, 2011
1 parent bd8fac5 commit b50622a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
26 changes: 10 additions & 16 deletions index.js
Expand Up @@ -3,6 +3,7 @@
*/
var redis = require('./deps/node-redis'),
events = require('events'),
uuid = require('node-uuid'),
util = require('util');

/**
Expand Down Expand Up @@ -60,26 +61,19 @@ exports.Queue = Queue;
Queue.prototype.push = function (payload, callback) {
var self = this;

// Get an ID from redis
this.client.incr(this.prefix + 'id:' + this.name, function (error, id) {
// Push the job.
self.client.rpush(self.prefix + 'queue:' + self.name, JSON.stringify({
id: uuid(),
payload: payload,
error_count: 0,
errors: [],
modified: Date.now()
}), function (error, length) {
if (error) {
return handleError(error, callback);
}

// Push the job.
self.client.rpush(self.prefix + 'queue:' + self.name, JSON.stringify({
id: id,
payload: payload,
error_count: 0,
errors: [],
modified: Date.now()
}), function (error, length) {
if (error) {
return handleError(error, callback);
}

if (callback) callback(null, id);
});
if (callback) callback(null, id);
});
};

Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -4,5 +4,8 @@
"version": "0.1.1",
"author": "Tim Smart",
"engine": [ "node >=0.3.6" ],
"main": "./"
"main": "./",
"dependencies": {
"node-uuid": ">1.1.0"
}
}

0 comments on commit b50622a

Please sign in to comment.