如何混合 SQL DB 与键值存储(即 Redis)

发布于 2024-08-20 16:47:12 字数 774 浏览 7 评论 0原文

我正在检查我的代码并意识到我花费了大量时间

  1. 从数据库中获取行,
  2. 格式化为 XML,
  3. AJAX GET到浏览器,然后
  4. 转换回散列 JavaScript 对象作为我的本地数据存储。

在更新时,我必须反转该过程(除了使用 POST 而不是 XML。)

刚开始研究 Redis,我认为我可以节省大量时间,将对象保存在服务器上的键值存储中,并且只是使用JSON直接传输到JS客户端。但我脆弱的头脑无法预料我离开 SQL DB 会放弃什么(即我害怕放弃 GROUP BY/HAVING 查询)

对于我的数据,我有:

  • 多对多关系,即 obj-标签、对象组等
  • 通过组合查询对象,即 WHERE tag IN ('a', 'b','c') AND group in ('x','y')
  • 自连接,即每个对象的所有标签 WHERE tag='a' (sql group_concat())
  • 很多外连接,即 OUTER JOIN rating ON o.id = rating.obj_id
  • 和 feeds,这似乎是 REDIS 的强项

如何成功地混合键值和键值? SQL 数据库?

例如,使用 SQL RANGE 查询将 REDIS 集中的大量 obj.Id 与 SQL 数据连接起来是很实用的(即 WHERE obj.id IN (1,4,6,7,8,34,876,9879,567,345, ...),反之亦然?

欢迎提出想法/建议。

I'm reviewing my code and realize I spend a tremendous amount of time

  1. taking rows from a database,
  2. formatting as XML,
  3. AJAX GET to browser, and then
  4. converting back into a hashed javascript object as my local datastore.

On updates, I have to reverse the process (except using POST instead of XML.)

Having just started looking at Redis, I'm thinking I can save a tremendous amount of time keeping the objects in a key-value store on the server and just using JSON to transfer directly to JS client. But my feeble mind can't anticipate what I'm giving up by leaving a SQL DB (i.e. I'm scared to give up the GROUP BY/HAVING queries)

For my data, I have:

  • many-many relationships, i.e. obj-tags, obj-groups, etc.
  • query objects by a combination of such, i.e. WHERE tag IN ('a', 'b','c') AND group in ('x','y')
  • self joins, i.e. ALL the tags for each object WHERE tag='a' (sql group_concat())
  • a lot of outer joins, i.e. OUTER JOIN rating ON o.id = rating.obj_id
  • and feeds, which seem to be a strong point in REDIS

How do you successfully mix key-value & SQL DBs?

For example, is practical to join a large list of obj.Ids from a REDIS set with SQL data using a SQL RANGE query (i.e. WHERE obj.id IN (1,4,6,7,8,34,876,9879,567,345, ...), or vice versa?

ideas/suggestions welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

偷得浮生 2024-08-27 16:47:12

您可能想看看 MongoDB。它适用于 JSON 风格的对象,并附带 SQL 之类的索引和索引。查询。 Redis更适合存储列表等数据结构。当您想要简单的查找而不是复杂的查询时。

You may want to take a look at MongoDB. It works with JSON style objects, and comes with SQL like indexing & querying. Redis is more suitable for storing data structures likes lists & sets, when you want a simple lookup instead of a complex query.

埋情葬爱 2024-08-27 16:47:12

现在实际的问题更加明确了(即,您花费大量时间编写重复的转换代码以从一层/表示移动到下一层),也许您可​​以考虑编写(或谷歌搜索)一些自动化的东西,也许?

Google 返回了大量“将表转换为 XML”(以及相反)的结果,这有帮助吗?直接从表到键/值对的东西会更好吗?您是否尝试过以通用的方式解决这个问题?

Now that the actual problem is more defined (i.e. you spend a lot of time writing repetitive conversion code to move from one layer/representation to the next) maybe you could consider writing (or googling for) something that automatizes this, maybe?

Googles returns plenty of results for "convert table to XML" (and the reverse), would this help? Would something going directly from table to key/value pairs be better? Have you tried tackling this problem in a generalized way?

高冷爸爸 2024-08-27 16:47:12

当您说“我花费了大量时间”时,您的意思是这是大量的开发时间,还是指计算时间?

就我个人而言,我对将 RDBMS 与非 RDBMS 解决方案混合使用持谨慎态度,因为当两种不同的范例发生冲突时,这可能会产生问题。

When you say "I spend a tremendous amount of time" do you mean this is a lot of development time, or are you referring to computing time?

Personally I'd be wary of mixing a RDBMS with a non-RDBMS solution, because this will probably create problems when the two different paradigms clash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文