Skip to content

Commit

Permalink
Update Scripts.js to not create a new script on every call. OptimalBi…
Browse files Browse the repository at this point in the history
…ts#426

NOTES: this will still violate redis cluster rules of each script explicitly defining the keys it writes to in the KEYS array, howerver the current implementation also does this and this should fix the growing lua_memory_cache issue.
  • Loading branch information
joeandrews authored Jan 17, 2017
1 parent 9a18606 commit b6eb06c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ var scripts = {
' end',
' return nil',
'end',
['local items = redis.call("LRANGE",', keyVar, ' , 0, -1)'].join(''),
['local splitKey = split(', keyVar, ' , ":")'].join(''),
'local items = redis.call("LRANGE", splitKey[1]..":"..splitKey[2]..":active" , 0, -1)',
[operator, ' item_in_list(items, ', argVar, ')'].join('')
].join('\n');
},
Expand Down Expand Up @@ -300,7 +301,7 @@ var scripts = {
var keyVar = ['"', job.queue.toKey('active'), '"'].join('');
var argVar = ['"', job.jobId, '"'].join('');
var isJobInList = this._isJobInList(keyVar, argVar, 'if');
var lockAcquired = ['and redis.call("HSET", "', queue.toKey(job.jobId), '", "lockAcquired", "1")'].join('');
var lockAcquired = 'and redis.call("HSET", splitKey[1]..":"..splitKey[2]..":active", "lockAcquired", "1")';
var success = 'then return 1 else return 0 end';
var opts = {
lockScript: function(lockScript) {
Expand Down

0 comments on commit b6eb06c

Please sign in to comment.