@vbarbarosh/node-helpers
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -5,3 +5,3 @@ { | ||
"name": "@vbarbarosh/node-helpers", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A set of helpers for JavaScript/Node.js", | ||
@@ -35,4 +35,8 @@ "files": [ | ||
"mocha": "^10.2.0", | ||
"throttle": "^1.0.3" | ||
"throttle": "^1.0.3", | ||
"redis-v1": "npm:redis@1", | ||
"redis-v2": "npm:redis@2", | ||
"redis-v3": "npm:redis@3", | ||
"redis-v4": "npm:redis@4" | ||
} | ||
} |
@@ -18,3 +18,3 @@ const assert = require('assert'); | ||
const tmp = fs_path_resolve(d, 'a/b/c/d/e/f/g/h'); | ||
await Promise.all(Array(10).fill(tmp).map(async function (v, i) { | ||
await Promise.all(Array(10).fill(tmp).map(async function () { | ||
await fs_mkdirp(tmp); | ||
@@ -21,0 +21,0 @@ assert(await fs_fi(tmp).then(v => v.isDirectory())); |
async function redis_lshift(redis, queue, limit = 1) | ||
{ | ||
const last = limit - 1; | ||
const [items] = await redis.multi().lrange(queue, 0, last).ltrim(queue, limit, -1).exec_p(); | ||
if (redis.lrange) { | ||
const [items] = await new Promise(function (resolve, reject) { | ||
redis.multi().lrange(queue, 0, last).ltrim(queue, limit, -1).exec(function (error, out) { | ||
error ? reject(error) : resolve(out); | ||
}); | ||
}); | ||
return items; | ||
} | ||
// redis@4 | ||
const [items] = await redis.multi().LRANGE(queue, 0, last).LTRIM(queue, limit, -1).exec(); | ||
return items; | ||
@@ -6,0 +15,0 @@ } |
async function redis_zshift(redis, queue, limit = 1) | ||
{ | ||
const last = limit - 1; | ||
// noinspection JSUnresolvedFunction | ||
const [items] = await redis.multi().zrange(queue, 0, last).zremrangebyrank(queue, 0, last).exec_p(); | ||
if (redis.zrange) { | ||
const [items] = await new Promise(function (resolve, reject) { | ||
redis.multi().zrange(queue, 0, last).zremrangebyrank(queue, 0, last).exec(function (error, out) { | ||
error ? reject(error) : resolve(out); | ||
}); | ||
}); | ||
return items; | ||
} | ||
// redis@4 | ||
const [items] = await redis.multi().ZRANGE(queue, 0, last).ZREMRANGEBYRANK(queue, 0, last).exec(); | ||
return items; | ||
@@ -7,0 +15,0 @@ } |
63997
110
1822
6