1
0
mirror of https://github.com/redis/node-redis.git synced 2025-12-14 09:42:12 +03:00

feat(client): add CAS/CAD, DELEX, DIGEST support (#3123)

* feat: add digest command and tests

* feat: add delex command and tests

* feat: add more conditional options to SET update tests
This commit is contained in:
Pavel Pashov
2025-11-03 13:53:01 +02:00
committed by GitHub
parent 5a0a06df69
commit 2fdb6def45
7 changed files with 244 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
import { CommandParser } from "../client/parser";
import { NumberReply, Command, RedisArgument } from "../RESP/types";
export const DelexCondition = {
/**
* Delete if value equals match-value.
*/
IFEQ: "IFEQ",
/**
* Delete if value does not equal match-value.
*/
IFNE: "IFNE",
/**
* Delete if value digest equals match-digest.
*/
IFDEQ: "IFDEQ",
/**
* Delete if value digest does not equal match-digest.
*/
IFDNE: "IFDNE",
} as const;
type DelexCondition = (typeof DelexCondition)[keyof typeof DelexCondition];
export default {
IS_READ_ONLY: false,
/**
* Conditionally removes the specified key based on value or digest comparison.
*
* @param parser - The Redis command parser
* @param key - Key to delete
*/
parseCommand(
parser: CommandParser,
key: RedisArgument,
options?: {
/**
* The condition to apply when deleting the key.
* - `IFEQ` - Delete if value equals match-value
* - `IFNE` - Delete if value does not equal match-value
* - `IFDEQ` - Delete if value digest equals match-digest
* - `IFDNE` - Delete if value digest does not equal match-digest
*/
condition: DelexCondition;
/**
* The value or digest to compare against
*/
matchValue: RedisArgument;
}
) {
parser.push("DELEX");
parser.pushKey(key);
if (options) {
parser.push(options.condition);
parser.push(options.matchValue);
}
},
transformReply: undefined as unknown as () => NumberReply<1 | 0>,
} as const satisfies Command;