1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

feat: added support for new bitop operations (#3001)

refactored bitop tests, covered all operations

updated default docker version on all packages
This commit is contained in:
Pavel Pashov
2025-06-19 13:56:00 +03:00
committed by GitHub
parent 2b3140bb72
commit b52177752e
10 changed files with 77 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import BITOP from './BITOP';
import BITOP, { BitOperations } from './BITOP';
import { parseArgs } from './generic-transformers';
describe('BITOP', () => {
@@ -20,13 +20,77 @@ describe('BITOP', () => {
});
});
testUtils.testAll('bitOp', async client => {
for (const op of ['AND', 'OR', 'XOR'] as BitOperations[]) {
testUtils.testAll(`bitOp ${op} with non-existing keys`, async client => {
assert.equal(
await client.bitOp(op, '{tag}destKey', ['{tag}key1', '{tag}key2']),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
testUtils.testAll(`bitOp ${op} with existing keys`, async client => {
await client.set('{tag}key1', 'value1');
await client.set('{tag}key2', 'value2');
assert.equal(
await client.bitOp(op, '{tag}destKey', ['{tag}key1', '{tag}key2']),
6
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}
// NOT operation requires only one key
testUtils.testAll('bitOp NOT with non-existing keys', async client => {
assert.equal(
await client.bitOp('AND', '{tag}destKey', '{tag}key'),
await client.bitOp('NOT', '{tag}destKey', '{tag}key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
testUtils.testAll('bitOp NOT with existing keys', async client => {
await client.set('{tag}key', 'value');
assert.equal(
await client.bitOp('NOT', '{tag}destKey', '{tag}key'),
5
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
// newer operations supported since Redis 8.2
for (const op of ['DIFF', 'DIFF1', 'ANDOR', 'ONE'] as BitOperations[]) {
testUtils.testAll(`bitOp ${op} with non-existing keys`, async client => {
assert.equal(
await client.bitOp(op, '{tag}destKey', ['{tag}key1', '{tag}key2']),
0
);
}, {
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
});
testUtils.testAll(`bitOp ${op} with existing keys`, async client => {
await client.set('{tag}key1', 'value1');
await client.set('{tag}key2', 'value2');
assert.equal(
await client.bitOp(op, '{tag}destKey', ['{tag}key1', '{tag}key2']),
6
);
}, {
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
});
}
});