Skip to content

Commit

Permalink
Key type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeveloper committed Mar 7, 2014
1 parent 2cdad5f commit 2e3c99b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/warlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ module.exports = function(redis){

/**
* Set a lock key
* @param {object} redis node-redis client.
* @param {string} key Name for the lock key. String please.
* @param {integer} ttl Time in milliseconds for the lock to live.
* @param {Function} cb
*/
warlock.lock = function(key, ttl, cb) {
cb = cb || function(){};

if (typeof key !== 'string') return cb('lock key must be string');

scripty.loadScriptFile('lock', __dirname + '/lua/lock.lua', function(err, lock){
var timestamp = Date.now();
lock.run(3, warlock.makeKey(key), ttl, timestamp, function(err, lockSet) {
Expand All @@ -41,6 +42,8 @@ module.exports = function(redis){
warlock.unlock = function(key, timestamp, cb) {
cb = cb || function(){};

if (typeof key !== 'string') return cb('lock key must be string');

scripty.loadScriptFile('parityDel', __dirname + '/lua/parityDel.lua', function(err, parityDel){
if (err) return cb(err);

Expand Down

0 comments on commit 2e3c99b

Please sign in to comment.