mirror of
https://github.com/lingble/safe-redis-leader.git
synced 2025-10-30 04:02:24 +00:00
fix: build
This commit is contained in:
27
src/atomicGetIsEqualDelete.ts
Normal file
27
src/atomicGetIsEqualDelete.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { readFile as fsReadFile } from "fs";
|
||||
import IORedis from "ioredis";
|
||||
import { promisify } from "util";
|
||||
|
||||
const readFile = promisify(fsReadFile);
|
||||
|
||||
type getIsEqualDeleteType = {
|
||||
getIsEqualDelete?: (key: IORedis.KeyType, id: string) => Promise<boolean>;
|
||||
};
|
||||
|
||||
export async function atomicGetIsEqualDelete(
|
||||
asyncRedis: IORedis.Redis & getIsEqualDeleteType,
|
||||
key: IORedis.KeyType,
|
||||
id: string,
|
||||
): Promise<boolean> {
|
||||
if (!asyncRedis.getIsEqualDelete) {
|
||||
const file = await readFile(`${__dirname}/../luas/atomicGetIsEqualDelete.lua`, "utf8");
|
||||
|
||||
asyncRedis.defineCommand("getIsEqualDelete", {
|
||||
numberOfKeys: 1,
|
||||
lua: file,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await asyncRedis.getIsEqualDelete!(key, id);
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user