你好,我想知道在Redis中哪种类型的删除功能是正确的.代码如下所示.
/**
* Delete a key
* - _group_: generic
* - _complexity_: O(N) where N is the number of keys that will be removed. When a key to remove holds a value other than a string, the individual complexity for this key is O(M) where M is the number of elements in the list, set, sorted set or hash. Removing a single key that holds a string value is O(1).
* - _since_: 1.0.0
*/
del(...args: [...keys: RedisKey[], callback: Callback<number>]): Result<number, Context>;
del(...args: [keys: RedisKey[], callback: Callback<number>]): Result<number, Context>;
del(...args: [...keys: RedisKey[]]): Result<number, Context>;
del(...args: [keys: RedisKey[]]): Result<number, Context>;
所以我的函数是这样的
public async del(key: RedisKey[] | RedisKey) {
return this._redis.del(key)
}
以下是RedisKey声明
export declare type RedisKey = string | Buffer;
由于某些原因,不可能同时传递字符串或字符串array.
获取此错误
TS2769: No overload matches this call. Argument of type '[RedisKey | RedisKey[]]' is not assignable to parameter of type '[...keys: RedisKey[], callback: Callback<number>]'. Type at position 0 in source is not compatible with type at position 1 in target. Type 'RedisKey | RedisKey[]' is not assignable to type 'Callback<number>'. Type 'string' is not assignable to type 'Callback<number>'. Overload 2 of 4, '(...args: RedisKey[]): Promise<number>', gave the following error. Argument of type 'RedisKey | RedisKey[]' is not assignable to parameter of type 'RedisKey'. Type 'RedisKey[]' is not assignable to type 'RedisKey'. Type 'RedisKey[]' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 73 more. Overload 3 of 4, '(keys: RedisKey[]): Promise<number>', gave the following error. Argument of type 'RedisKey | RedisKey[]' is not assignable to parameter of type 'RedisKey[]'. Type 'string' is not assignable to type 'RedisKey[]'.
如果我只放RedisKey[]或RedisKey,它会像预期的那样工作,但它不会对这两种类型都起作用.请说明一下,由于有4个del()声明,我不确定发生了什么事?函数应该只接受字符串或字符串数组这两种类型,所以我只想删除redis中的一个键或多个键.