You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Add Redis 8.2 New Stream Commands (#3029)
* chore: update Redis version from 8.2-RC1-pre to 8.2-rc1 * feat: implement XDELEX command for Redis 8.2 * feat: implement XACKDEL command for Redis 8.2 * refactor: create shared stream deletion types for Redis 8.2 commands * feat: add Redis 8.2 deletion policies to XTRIM command * feat: add Redis 8.2 deletion policies to XADD commands * fix: correct XDELEX command method name and test parameter
This commit is contained in:
156
packages/client/lib/commands/XDELEX.spec.ts
Normal file
156
packages/client/lib/commands/XDELEX.spec.ts
Normal file
@@ -0,0 +1,156 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import XDELEX from "./XDELEX";
|
||||
import { parseArgs } from "./generic-transformers";
|
||||
import testUtils, { GLOBAL } from "../test-utils";
|
||||
import {
|
||||
STREAM_DELETION_POLICY,
|
||||
STREAM_DELETION_REPLY_CODES,
|
||||
} from "./common-stream.types";
|
||||
|
||||
describe("XDELEX", () => {
|
||||
describe("transformArguments", () => {
|
||||
it("string - without policy", () => {
|
||||
assert.deepEqual(parseArgs(XDELEX, "key", "0-0"), [
|
||||
"XDELEX",
|
||||
"key",
|
||||
"IDS",
|
||||
"1",
|
||||
"0-0",
|
||||
]);
|
||||
});
|
||||
|
||||
it("string - with policy", () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(XDELEX, "key", "0-0", STREAM_DELETION_POLICY.KEEPREF),
|
||||
["XDELEX", "key", "KEEPREF", "IDS", "1", "0-0"]
|
||||
);
|
||||
});
|
||||
|
||||
it("array - without policy", () => {
|
||||
assert.deepEqual(parseArgs(XDELEX, "key", ["0-0", "1-0"]), [
|
||||
"XDELEX",
|
||||
"key",
|
||||
"IDS",
|
||||
"2",
|
||||
"0-0",
|
||||
"1-0",
|
||||
]);
|
||||
});
|
||||
|
||||
it("array - with policy", () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(XDELEX, "key", ["0-0", "1-0"], STREAM_DELETION_POLICY.DELREF),
|
||||
["XDELEX", "key", "DELREF", "IDS", "2", "0-0", "1-0"]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testAll(
|
||||
`XDELEX non-existing key - without policy`,
|
||||
async (client) => {
|
||||
const reply = await client.xDelEx("{tag}stream-key", "0-0");
|
||||
assert.deepEqual(reply, [STREAM_DELETION_REPLY_CODES.NOT_FOUND]);
|
||||
},
|
||||
{
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
}
|
||||
);
|
||||
|
||||
testUtils.testAll(
|
||||
`XDELEX existing key - without policy`,
|
||||
async (client) => {
|
||||
const streamKey = "{tag}stream-key";
|
||||
const messageId = await client.xAdd(streamKey, "*", {
|
||||
field: "value",
|
||||
});
|
||||
|
||||
const reply = await client.xDelEx(
|
||||
streamKey,
|
||||
messageId,
|
||||
);
|
||||
assert.deepEqual(reply, [STREAM_DELETION_REPLY_CODES.DELETED]);
|
||||
},
|
||||
{
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
}
|
||||
);
|
||||
|
||||
testUtils.testAll(
|
||||
`XDELEX existing key - with policy`,
|
||||
async (client) => {
|
||||
const streamKey = "{tag}stream-key";
|
||||
const messageId = await client.xAdd(streamKey, "*", {
|
||||
field: "value",
|
||||
});
|
||||
|
||||
const reply = await client.xDelEx(
|
||||
streamKey,
|
||||
messageId,
|
||||
STREAM_DELETION_POLICY.DELREF
|
||||
);
|
||||
assert.deepEqual(reply, [STREAM_DELETION_REPLY_CODES.DELETED]);
|
||||
},
|
||||
{
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
}
|
||||
);
|
||||
|
||||
testUtils.testAll(
|
||||
`XDELEX acknowledge policy - with consumer group`,
|
||||
async (client) => {
|
||||
const streamKey = "{tag}stream-key";
|
||||
|
||||
// Add a message to the stream
|
||||
const messageId = await client.xAdd(streamKey, "*", {
|
||||
field: "value",
|
||||
});
|
||||
|
||||
// Create consumer group
|
||||
await client.xGroupCreate(streamKey, "testgroup", "0");
|
||||
|
||||
const reply = await client.xDelEx(
|
||||
streamKey,
|
||||
messageId,
|
||||
STREAM_DELETION_POLICY.ACKED
|
||||
);
|
||||
assert.deepEqual(reply, [STREAM_DELETION_REPLY_CODES.DANGLING_REFS]);
|
||||
},
|
||||
{
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
}
|
||||
);
|
||||
|
||||
testUtils.testAll(
|
||||
`XDELEX multiple keys`,
|
||||
async (client) => {
|
||||
const streamKey = "{tag}stream-key";
|
||||
const messageIds = await Promise.all([
|
||||
client.xAdd(streamKey, "*", {
|
||||
field: "value1",
|
||||
}),
|
||||
client.xAdd(streamKey, "*", {
|
||||
field: "value2",
|
||||
}),
|
||||
]);
|
||||
|
||||
const reply = await client.xDelEx(
|
||||
streamKey,
|
||||
[...messageIds, "0-0"],
|
||||
STREAM_DELETION_POLICY.DELREF
|
||||
);
|
||||
assert.deepEqual(reply, [
|
||||
STREAM_DELETION_REPLY_CODES.DELETED,
|
||||
STREAM_DELETION_REPLY_CODES.DELETED,
|
||||
STREAM_DELETION_REPLY_CODES.NOT_FOUND,
|
||||
]);
|
||||
},
|
||||
{
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] },
|
||||
}
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user