Azure Redis 缓存和 RedisJSON,可能的替代品

Azure Redis Cache and RedisJSON, possible alternatives

我正在考虑将 Azure Redis 缓存用于我们的一个应用程序。在某些情况下,我们需要存储纯 JSON,这是最好的 practices section clearly recommends against。我是 Redis 的新手,我正在研究满足我们要求的可能模式,我不确定我的方法是否违反了这些最佳实践。

我要实现的模式是这样的:

  1. Cosmos 数据库中的项目发生变化
  2. 更改提要针对更新的项目进行解析
  3. 更新的项目被序列化并写入 Redis
  4. 稍后查询系统时,首先查找缓存项。检索并反序列化(如果存在)。如果不存在,请查询 Cosmos。

SET 和 GET 将在应用程序的两个完全独立的部分中进行。永远不会有我检索、修改和设置的场景,因为 Cosmos 文档充当中间体并且永远不会触发同时写入。查询系统时,如果存在文档,则期望缓存始终是最新的。

我无法真正弄清楚的是,我的方法是否存在上述数据丢失的风险:

Worse yet, many applications would just GET the entire JSON string, deserialize it, manipulate it, re-serialize and SET it again at the application. This is an anti-pattern. There is a very real risk of losing data with this method.

他们继续建议 RedisJSON,必须在数据库级别激活。

不幸的是,Azure Redis 缓存似乎无法做到这一点,或者至少我在创建资源时或创建资源时都找不到任何文档或任何选项来执行此操作。

  1. 是否可以将 RedisJSON 与 Azure Redis 缓存一起使用?
  2. 如果不是 #1,是否有其他推荐的方法来使用 Redis 存储 JSON 数据,或者我建议的方法是一个可能的解决方案?

更新

我通过监听我想在 Azure 函数中缓存的容器的更改提要解决了这个问题。这种模式有一个单一的应用程序实例曾经写入一个唯一的文档,并且读取完全独立发生并且永远不会改变缓存的值。

如果插入或更新文档但未删除,则更改源会接收整个文档。由于接收了整个文档,在某些情况下很容易使缓存无效或添加软删除值以将其完全删除。

Is it possible to use RedisJSON with Azure Redis Cache?

您可以使用 Redis Cloud 在 Azure 上使用 RedisJSON 轻松创建 Redis,请参阅: https://redis.com/redis-enterprise-cloud/pricing/

Is it possible to use RedisJSON with Azure Redis Cache?

我认为 Azure Redis 不支持它 https://docs.microsoft.com/en-us/answers/questions/709524/when-can-expected-redis-json-module-support-with-a.html

我也在为 azure Redis 缓存实现一个解决方案来保存 JSON 文档,我将转义的 json 字符串保存到 Redis 值