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:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
node-version: ["18", "20", "22"]
|
node-version: ["18", "20", "22"]
|
||||||
redis-version: ["rs-7.2.0-v13", "rs-7.4.0-v1", "8.0.2"]
|
redis-version: ["rs-7.2.0-v13", "rs-7.4.0-v1", "8.0.2", "8.2-M01-pre"]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
|
@@ -4,7 +4,7 @@ import RedisBloomModules from '.';
|
|||||||
export default TestUtils.createFromConfig({
|
export default TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
export const GLOBAL = {
|
export const GLOBAL = {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'node:assert';
|
import { strict as assert } from 'node:assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import BITOP from './BITOP';
|
import BITOP, { BitOperations } from './BITOP';
|
||||||
import { parseArgs } from './generic-transformers';
|
import { parseArgs } from './generic-transformers';
|
||||||
|
|
||||||
describe('BITOP', () => {
|
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(
|
assert.equal(
|
||||||
await client.bitOp('AND', '{tag}destKey', '{tag}key'),
|
await client.bitOp('NOT', '{tag}destKey', '{tag}key'),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}, {
|
}, {
|
||||||
client: GLOBAL.SERVERS.OPEN,
|
client: GLOBAL.SERVERS.OPEN,
|
||||||
cluster: GLOBAL.CLUSTERS.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 { NumberReply, Command, RedisArgument } from '../RESP/types';
|
||||||
import { RedisVariadicArgument } from './generic-transformers';
|
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 {
|
export default {
|
||||||
IS_READ_ONLY: false,
|
IS_READ_ONLY: false,
|
||||||
/**
|
/**
|
||||||
* Performs bitwise operations between strings
|
* Performs bitwise operations between strings
|
||||||
* @param parser - The Redis command parser
|
* @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 destKey - Destination key to store the result
|
||||||
* @param key - Source key(s) to perform operation on
|
* @param key - Source key(s) to perform operation on
|
||||||
*/
|
*/
|
||||||
|
@@ -174,7 +174,7 @@ export class SentinelFramework extends DockerBase {
|
|||||||
this.#testUtils = TestUtils.createFromConfig({
|
this.#testUtils = TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
this.#nodeMap = new Map<string, ArrayElement<Awaited<ReturnType<SentinelFramework['spawnRedisSentinelNodes']>>>>();
|
this.#nodeMap = new Map<string, ArrayElement<Awaited<ReturnType<SentinelFramework['spawnRedisSentinelNodes']>>>>();
|
||||||
this.#sentinelMap = new Map<string, ArrayElement<Awaited<ReturnType<SentinelFramework['spawnRedisSentinelSentinels']>>>>();
|
this.#sentinelMap = new Map<string, ArrayElement<Awaited<ReturnType<SentinelFramework['spawnRedisSentinelSentinels']>>>>();
|
||||||
|
@@ -9,7 +9,7 @@ import RedisBloomModules from '@redis/bloom';
|
|||||||
const utils = TestUtils.createFromConfig({
|
const utils = TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default utils;
|
export default utils;
|
||||||
|
@@ -6,7 +6,7 @@ import { EntraidCredentialsProvider } from './entraid-credentials-provider';
|
|||||||
export const testUtils = TestUtils.createFromConfig({
|
export const testUtils = TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
const DEBUG_MODE_ARGS = testUtils.isVersionGreaterThan([7]) ?
|
const DEBUG_MODE_ARGS = testUtils.isVersionGreaterThan([7]) ?
|
||||||
|
@@ -4,7 +4,7 @@ import RedisJSON from '.';
|
|||||||
export default TestUtils.createFromConfig({
|
export default TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
export const GLOBAL = {
|
export const GLOBAL = {
|
||||||
|
@@ -5,7 +5,7 @@ import { RespVersions } from '@redis/client';
|
|||||||
export default TestUtils.createFromConfig({
|
export default TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
export const GLOBAL = {
|
export const GLOBAL = {
|
||||||
|
@@ -4,7 +4,7 @@ import TimeSeries from '.';
|
|||||||
export default TestUtils.createFromConfig({
|
export default TestUtils.createFromConfig({
|
||||||
dockerImageName: 'redislabs/client-libs-test',
|
dockerImageName: 'redislabs/client-libs-test',
|
||||||
dockerImageVersionArgument: 'redis-version',
|
dockerImageVersionArgument: 'redis-version',
|
||||||
defaultDockerVersion: '8.0.2'
|
defaultDockerVersion: '8.2-M01-pre'
|
||||||
});
|
});
|
||||||
|
|
||||||
export const GLOBAL = {
|
export const GLOBAL = {
|
||||||
|
Reference in New Issue
Block a user