Skip to content

Commit 90ab01f

Browse files
committed
feat: add digest command and tests
1 parent 96a8a84 commit 90ab01f

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { strict as assert } from "node:assert";
2+
import DIGEST from "./DIGEST";
3+
import { parseArgs } from "./generic-transformers";
4+
import testUtils, { GLOBAL } from "../test-utils";
5+
6+
describe("DIGEST", () => {
7+
describe("transformArguments", () => {
8+
it("digest", () => {
9+
assert.deepEqual(parseArgs(DIGEST, "key"), ["DIGEST", "key"]);
10+
});
11+
});
12+
13+
testUtils.testAll(
14+
"existing key",
15+
async (client) => {
16+
await client.set("key{tag}", "value");
17+
assert.equal(typeof await client.digest("key{tag}"), "string");
18+
},
19+
{
20+
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] },
21+
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] },
22+
}
23+
);
24+
25+
testUtils.testAll(
26+
"non-existing key",
27+
async (client) => {
28+
assert.equal(await client.digest("key{tag}"), null);
29+
},
30+
{
31+
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] },
32+
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] },
33+
}
34+
);
35+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { CommandParser } from "../client/parser";
2+
import { Command, RedisArgument, SimpleStringReply } from "../RESP/types";
3+
4+
export default {
5+
IS_READ_ONLY: true,
6+
/**
7+
* Returns the XXH3 hash of a string value.
8+
*
9+
* @param parser - The Redis command parser
10+
* @param key - Key to get the digest of
11+
*/
12+
parseCommand(parser: CommandParser, key: RedisArgument) {
13+
parser.push("DIGEST");
14+
parser.pushKey(key);
15+
},
16+
transformReply: undefined as unknown as () => SimpleStringReply,
17+
} as const satisfies Command;

packages/client/lib/commands/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import DBSIZE from './DBSIZE';
8484
import DECR from './DECR';
8585
import DECRBY from './DECRBY';
8686
import DEL from './DEL';
87+
import DIGEST from './DIGEST';
8788
import DUMP from './DUMP';
8889
import ECHO from './ECHO';
8990
import EVAL_RO from './EVAL_RO';
@@ -543,6 +544,8 @@ export default {
543544
decrBy: DECRBY,
544545
DEL,
545546
del: DEL,
547+
DIGEST,
548+
digest: DIGEST,
546549
DUMP,
547550
dump: DUMP,
548551
ECHO,

0 commit comments

Comments
 (0)