Permalink
Browse files

Use node-uuid instead of redis id coounters.

  • Loading branch information...
tim-smart committed Feb 21, 2011
1 parent bd8fac5 commit b50622a90eecc9a9f494b8af828ff938c9f62999
Showing with 14 additions and 17 deletions.
  1. +10 −16 index.js
  2. +4 −1 package.json
View
@@ -3,6 +3,7 @@
*/
var redis = require('./deps/node-redis'),
events = require('events'),
uuid = require('node-uuid'),
util = require('util');
/**
@@ -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);
});
};
View
@@ -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.