Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用IDistributedCache列出并删除给定组中的所有缓存项_C#_Redis_Asp.net Core 2.2_.net 4.7.2 - Fatal编程技术网

C# 使用IDistributedCache列出并删除给定组中的所有缓存项

C# 使用IDistributedCache列出并删除给定组中的所有缓存项,c#,redis,asp.net-core-2.2,.net-4.7.2,C#,Redis,Asp.net Core 2.2,.net 4.7.2,我将用户生成的一些密钥存储在IDistributedCache设置中 密钥的使用期限很长,如果用户知道其中的每一个密钥,则可以由用户手动撤销: public void ConfigureServices(IServiceCollection services) { services.AddDistributedMemoryCache(); //... } //ControllerBase: //Adding the key: await _cache.SetAsync(use

我将用户生成的一些密钥存储在
IDistributedCache
设置中

密钥的使用期限很长,如果用户知道其中的每一个密钥,则可以由用户手动撤销:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDistributedMemoryCache();
    //...
}

//ControllerBase:

//Adding the key:
await _cache.SetAsync(userKey, userId, new DistributedCacheEntryOptions 
{ 
    AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(10)
});

Removing the key:
await _cache.RemoveAsync(key);
现在,我想做的是能够列出缓存中仍然存在的由其中一个用户创建的所有密钥。此外,我希望能够批量删除它们

现在有这样的功能吗?
也许用取消代币?如何操作?

不,使用
IDistributedCache
一次只能使用一个键。大规模密钥收回和类似场景超出了此外观的范围。如果需要处理更高级的场景,那么应该使用适当的客户端直接连接到缓存。例如,对于Redis备份,您可以使用
StackExchange.Redis
包,并通过该包发出您喜欢的任何命令