1

我有两个设置为 CQRS 的服务 - 所以一个是仅查询服务,另一个是可以更改数据的命令服务。

这些服务由 MongoDB 提供支持,并且高度并行化——多个查询使用聚合框架,并且聚合起来会消耗大量连接——当它们实际上不断地重新读取相同的数据时。

所以我认为 Redis 非常适合 MongoDB 之上的缓存层。我正在使用CachingFramework.Redis构建StackExchange.Redis.

对于查询方法,我创建了一个键对象,将其序列化为一个字符串,然后使用FetchHashedAsync. 这似乎运作良好,我可以通过在写入发生时重建各种键来轻松更新/使缓存项无效 - 当键可以从主缓存项重建时。

当这不容易实现时,事情会变得更加复杂;也就是说,当我缓存一般过滤器查询的结果时。

到目前为止,我的方法是存储一个字典,将过滤器映射到作为结果从 MongoDB 获取的对象的主键 - 并将它们存储在一个IRedisDictionary实例中。

这似乎不是一个好主意 - 因为我看到超时:

StackExchange.Redis.RedisTimeoutException occurred
  HResult=-2146233083
  HelpLink=http://stackexchange.github.io/StackExchange.Redis/Timeouts
  Message=Timeout performing HSET audit:correlationIdByHash, inst: 2, mgr: ProcessReadQueue, err: never, queue: 609, qu: 0, qs: 456, qc: 153, wr: 0, wq: 0, in: 8192, ar: 1, clientName: WSP18652WN, serverEndpoint: Unspecified/localhost:6379, keyHashSlot: 12790, IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=9,Free=32758,Min=8,Max=32767) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts)
  Source=StackExchange.Redis
  StackTrace:
       at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
       at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
       at StackExchange.Redis.RedisDatabase.HashSet(RedisKey key, RedisValue hashField, RedisValue value, When when, CommandFlags flags)
       at CachingFramework.Redis.RedisObjects.RedisDictionary`2.Add(TK key, TV value)
       at CachingFramework.Redis.RedisObjects.RedisDictionary`2.set_Item(TK key, TV value)
       at SPMO.Providers.Audit.AuditIndex.UpdateIndexImpl(Int32 keyHash, Guid correlationId) in E:\dev\SPMO\trunk\Providers\SPMO.Providers\Audit\AuditIndex.cs:line 61
  InnerException: 

有没有更好的方法来解决这个问题?

4

0 回答 0