-
-
Save francaguilar/4fdb5a692a91bfadfd5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cleverPush="\ | |
local arguments=ARGV\n\ | |
local max_mem=tonumber(table.remove(arguments))\n\ | |
local queue=KEYS[1]\n\ | |
local s=redis.call('info','memory')\n\ | |
local mem=tonumber(string.match(s,'used_memory:(.-)\\r\\n'))\n\ | |
if mem<(max_mem) then\n\ | |
return redis.call('lpush', queue, unpack(arguments))\n\ | |
else\n\ | |
return {err='Max queue size reached: infomem: '..tostring(mem)..' max_mem: '..tostring(max_mem)}\n\ | |
end\n\ | |
"; | |
function put(key, objs, callback) { | |
'use strict'; | |
//logger.debug('Insert Task', { op: 'PUT', userID: obj.user, correlator: obj.traceID, transid: obj.id, | |
// arguments: [ key, obj ] }); | |
//Legacy (convert obj into an array) | |
if (!util.isArray(objs)) { | |
var array = [objs] | |
objs = array; | |
} | |
//Parse objects | |
var parsedObjs = objs.map(function(obj) { | |
return JSON.stringify(obj) | |
}); | |
var db = dbCluster.getDb(); | |
var evalArgs = [cleverPush, 1, key].concat(parsedObjs).concat([configGlobal.redisMaxMemory, callback]); | |
db.eval.apply(db, evalArgs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment