diff --git a/src/index.ts b/src/index.ts index 746d8a0..4c17a7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -427,6 +427,11 @@ export class Evaluator { [__getKey(flag, $3), key], { result: { promise: true } } ), + delall: (key, flag) => $9.apply( + undefined, + [__getKey(flag, $3), key], + { result: { promise: true } } + ), len: (key, flag) => $6.apply( undefined, [__getKey(flag, $3), key], @@ -443,6 +448,7 @@ export class Evaluator { store.g = store.get; store.s = store.set; store.d = store.del; + store.da = store.delall; store.l = store.len; global.s = store; global.p = permissions; @@ -476,15 +482,16 @@ export class Evaluator { } `, [ - new Reference(store.get), - new Reference(store.set), - new Reference(store.del), - new ExternalCopy(msg).copyInto(), - new ExternalCopy(permissions).copyInto(), - new Reference(this.fetchImplement.bind(this, potatData)), - new Reference(store.len), - new Reference(store.ex), - new Reference(this.runCommand.bind(this)), + new Reference(store.get), // $0 + new Reference(store.set), // $1 + new Reference(store.del), // $2 + new ExternalCopy(msg).copyInto(), // $3 + new ExternalCopy(permissions).copyInto(), // $4 + new Reference(this.fetchImplement.bind(this, potatData)), // $5 + new Reference(store.len), // $6 + new Reference(store.ex), // $7 + new Reference(this.runCommand.bind(this)), // $8 + new Reference(store.delall), // $9 ], ); diff --git a/src/store/redis.ts b/src/store/redis.ts index e25d343..89d14b3 100644 --- a/src/store/redis.ts +++ b/src/store/redis.ts @@ -72,6 +72,10 @@ class PotatStore { return this.#client.hdel(key, ...fields); } + public async del(key: string | Buffer): Promise { + return this.#client.del(key); + } + public async hmget( primaryKey: string, key: string, diff --git a/src/store/store.ts b/src/store/store.ts index 39ac2c9..1896d94 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -49,6 +49,16 @@ const del = async ( return redis.hdel(privateKey, key); }; +const delall = async ( + privateKey: string, +): Promise => { + if (!redis.ready) { + throw new Error('Redis store is not initialized'); + } + + return redis.del(privateKey); +}; + const ex = async ( privateKey: string, key: string, @@ -74,6 +84,7 @@ export const store = { get, set, del, + delall, len, ex, };