You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +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:
@@ -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] },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -2,14 +2,14 @@ import { CommandParser } from '../client/parser';
|
||||
import { NumberReply, Command, RedisArgument } from '../RESP/types';
|
||||
import { RedisVariadicArgument } from './generic-transformers';
|
||||
|
||||
export type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT';
|
||||
export type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT' | 'DIFF' | 'DIFF1' | 'ANDOR' | 'ONE';
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: false,
|
||||
/**
|
||||
* Performs bitwise operations between strings
|
||||
* @param parser - The Redis command parser
|
||||
* @param operation - Bitwise operation to perform: AND, OR, XOR, NOT
|
||||
* @param operation - Bitwise operation to perform: AND, OR, XOR, NOT, DIFF, DIFF1, ANDOR, ONE
|
||||
* @param destKey - Destination key to store the result
|
||||
* @param key - Source key(s) to perform operation on
|
||||
*/
|
||||
|
Reference in New Issue
Block a user