Node redis (#13500)

* refactor: start migrating to node-redis

* few more zset fixes

* fix: db.scan

* fix: list methods

* fix set methods

* fix: hash methods

* use hasOwn, remove cloning

* sorted set fixes

* fix: so data is converted to strings before saving

otherwise node-redis throws below error
TypeError: "arguments[2]" must be of type "string | Buffer", got number instead.

* chore: remove comments

* fix: zrank string param

* use new close

* chore: up dbsearch

* test: add log

* test: more log

* test: log failing test

* test: catch errors in formatApiResponse

add await so exception goes to catch

* tetst: add log

* fix: dont set null/undefined values

* test: more fixes
This commit is contained in:
Barış Uşaklı
2025-06-18 13:04:57 -04:00
committed by GitHub
parent 3f7d415744
commit 14043ab0fd
21 changed files with 307 additions and 305 deletions

View File

@@ -10,7 +10,7 @@ module.exports = function (module) {
if (!value.length) {
return;
}
await module.client.sadd(key, value);
await module.client.sAdd(key, value.map(String));
};
module.setsAdd = async function (keys, value) {
@@ -18,7 +18,7 @@ module.exports = function (module) {
return;
}
const batch = module.client.batch();
keys.forEach(k => batch.sadd(String(k), String(value)));
keys.forEach(k => batch.sAdd(String(k), String(value)));
await helpers.execBatch(batch);
};
@@ -34,57 +34,57 @@ module.exports = function (module) {
}
const batch = module.client.batch();
key.forEach(k => batch.srem(String(k), value));
key.forEach(k => batch.sRem(String(k), value.map(String)));
await helpers.execBatch(batch);
};
module.setsRemove = async function (keys, value) {
const batch = module.client.batch();
keys.forEach(k => batch.srem(String(k), value));
keys.forEach(k => batch.sRem(String(k), String(value)));
await helpers.execBatch(batch);
};
module.isSetMember = async function (key, value) {
const result = await module.client.sismember(key, value);
const result = await module.client.sIsMember(key, String(value));
return result === 1;
};
module.isSetMembers = async function (key, values) {
const batch = module.client.batch();
values.forEach(v => batch.sismember(String(key), String(v)));
values.forEach(v => batch.sIsMember(String(key), String(v)));
const results = await helpers.execBatch(batch);
return results ? helpers.resultsToBool(results) : null;
};
module.isMemberOfSets = async function (sets, value) {
const batch = module.client.batch();
sets.forEach(s => batch.sismember(String(s), String(value)));
sets.forEach(s => batch.sIsMember(String(s), String(value)));
const results = await helpers.execBatch(batch);
return results ? helpers.resultsToBool(results) : null;
};
module.getSetMembers = async function (key) {
return await module.client.smembers(key);
return await module.client.sMembers(key);
};
module.getSetsMembers = async function (keys) {
const batch = module.client.batch();
keys.forEach(k => batch.smembers(String(k)));
keys.forEach(k => batch.sMembers(String(k)));
return await helpers.execBatch(batch);
};
module.setCount = async function (key) {
return await module.client.scard(key);
return await module.client.sCard(key);
};
module.setsCount = async function (keys) {
const batch = module.client.batch();
keys.forEach(k => batch.scard(String(k)));
keys.forEach(k => batch.sCard(String(k)));
return await helpers.execBatch(batch);
};
module.setRemoveRandom = async function (key) {
return await module.client.spop(key);
return await module.client.sPop(key);
};
return module;