StackExchange.Redis - 在哈希集或搜索键上实现过期 - 良好的性能

maz*_*maz 5 .net c# caching redis stackexchange.redis

我有 StackExchange.Redis 使用的 redis 缓存。

首先,redis包含hashSets,我尝试为hashSet中的键设置过期时间,但我读了这篇文章(https://github.com/antirez/redis/issues/167#issuecomment-2559040)并意识到这是不可能的。

所以我改变了我的redis缓存,现在它只包含键,值对。过期的问题实际上已经解决了:-)。

但缓存的另一个功能是让所有键都以某个 前缀开头。

首先我尝试使用 Keys 函数,但这里不推荐使用,并且在某些情况下会出现超时异常。

阅读后,我选择使用包含函数 SearchKey(string pattren) 的 StackExchange.Redis.Extention.Core。(请参阅https://www.nuget.org/packages/StackExchange.Redis.Extensions.Core

SearchKey 功能工作正常,唯一的问题是性能不佳。

对于 50,0000 个密钥,searchKey 函数需要:3~ 秒。

对于 100,0000 个密钥,searchKey 函数需要:6~ 秒。

对于 200,0000 个密钥,searchKey 函数需要:12~ 秒。

在生产中,我的 Redis 缓存将包含200,000 - 300,000 个密钥,因此性能很差。

有什么想法,解决它吗?

感谢!