Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/memcache-client/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type StoreParams = string | number | Buffer | Record<string, unknown>;

type CommonCommandOption = Readonly<{ noreply?: boolean; expectedResponses?: number }>;

type StoreCommandOptions = CommonCommandOption & { ignoreNotStored?: boolean } & Readonly<{
type StoreCommandOptions = CommonCommandOption & { ignoreNotStored?: boolean; ignoreExists?: boolean } & Readonly<{
lifetime?: number;
compress?: boolean;
}>;
Expand Down Expand Up @@ -332,6 +332,9 @@ export class MemcacheClient extends EventEmitter {
callback?: OperationCallback<Error, string[]>
): Promise<string[]> {
assert(options?.casUniq, "Must provide options.casUniq for cas store command");
if (options.ignoreExists === undefined) {
options = { ...options, ignoreExists: this.options.ignoreExists };
}
return this.store("cas", key, value, options, callback);
}

Expand Down Expand Up @@ -701,6 +704,9 @@ export class MemcacheClient extends EventEmitter {
if (options.ignoreNotStored === true && err.message === "NOT_STORED") {
return resolve("ignore NOT_STORED");
}
if (options.ignoreExists === true && err.message === "EXISTS") {
return resolve("ignore EXISTS");
}
return reject(err);
}
if (result) {
Expand Down
1 change: 1 addition & 0 deletions packages/memcache-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type PackedData = {
export type MemcacheClientOptions = {
server: ServerDefinition | SingleServerEntry | MultipleServerEntry;
ignoreNotStored?: boolean;
ignoreExists?: boolean;
lifetime?: number;
noDelay?: boolean;
cmdTimeout?: number;
Expand Down