【问题标题】:Confused about Redis structuring of data对 Redis 数据结构感到困惑
【发布时间】:2023-03-26 19:43:01
【问题描述】:

我有以下 JSON 数据结构需要缓存在 Redis 中:

{
    siteId:1,
    zoneId:1,
    adWidth:100,
    adHeight:100,
    totalVisibleAds:1,
    ads:[{
        id:1,
        link:"...",
        imageLink:"...",
        altText:"Google",
            views:100       
    },
    {
        id:1,
        link:"...",
        imageLink:"...",
        altText:"Google",
            views:100       
    }]
}
  • 我需要能够通过siteId查询以“Redis”的方式返回这个结构。
  • 增加views 字段
  • 从 ads 数组中随机选择一个广告
  • 在特定日期使整个对象过期

如果我将哈希存储为site:1:zone:1,我如何仅通过site:1 获得?还是我只是在想这完全错了?

【问题讨论】:

    标签: redis nosql


    【解决方案1】:

    您应该考虑在您的案例中使用 MongoDB,因为您需要存储嵌套数据并使用嵌套索引进行查询。如果性能是一个问题,mongoDB 查询通常很快。

    参考http://docs.mongodb.org/manual/tutorial/model-tree-structures-with-nested-sets/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多