如何在Redis中更新多个键值对!

时间:2023-01-20 07:37:59

So for my application I am considering adding Redis. I am new to Redis and have not been able to come up with a good way to update the information I need to constantly update, so I was wondering if anyone could help.

因此,对于我的应用程序,我正在考虑添加Redis。我是Redis的新手,没有一个好的方法来更新我需要不断更新的信息,所以我想知道是否有人能帮忙。

In my app, I have a many to many relationship between posts and topics. Each post also has a score.

在我的应用中,我的文章和主题之间有很多很多的关系。每个帖子都有一个分数。

My first thought was to set up my Redis db so each topic was an ordered set of post_ids and each post_id in that ordered set was associated with that post's score. Posts are now each their own hash that associates their ID with the information about the post (score, user_id, url). I am periodically updating the score of that post, which brings me to my problem. When I update the score of that post, according to the setup I have now, I need to go and find every topic that post is associated with and update the score for the post_id in that topic's ordered set. This does not seem like the best solution if I were to scale the app to millions of posts and millions of topics.

我的第一个想法是设置Redis db,因此每个主题都是一个有序的post_id集合,并且该有序集合中的每个post_id都与该post的得分相关联。现在,每个贴子都是自己的散列,它们将自己的ID与有关贴子的信息(score、user_id、url)关联起来。我定期更新那个帖子的得分,这让我想起了我的问题。当我更新后的分数,根据我现在的设置,我需要去找每一个主题,发布和更新有关分数的post_id主题的有序集。这似乎不像最好的解决办法如果我是应用程序扩展到数以百万计的帖子和数以百万计的主题。

Is there a better setup for my Redis db that I am not seeing or should I just stick with my SQL db?

对于我没有看到的Redis db,是否有更好的设置,或者应该只使用SQL db?

1 个解决方案

#1


2  

The design is solid for storing posts and keeping track of posts per topic by score.

这一设计是可靠的,用于存储文章和跟踪每个主题的文章得分。

In terms of scalability, I don't see a problem with millions of topics and posts but you'd be safer doing some back-of-the-napkin math to have a sense of stuff like the throughout you'll need and amount of memory required. Also, from the looks of it out looks that you can easily use two databases - one for posts and one for topics - to better handle potential load.

在可伸缩性方面,我不认为有数百万个主题和帖子存在问题,但是做一些粗略的数学计算会更安全一些,比如你需要的东西,以及所需的记忆量。此外,从外观来看,您可以轻松地使用两个数据库——一个用于post,一个用于主题——以更好地处理潜在的负载。

Lastly, no - if Redis isn't enough, I don't see how you'll pull this off with decent performance and scale with a SQL database.

最后,不,如果Redis还不够,我不知道如何使用SQL数据库实现出色的性能和可伸缩性能。

#1


2  

The design is solid for storing posts and keeping track of posts per topic by score.

这一设计是可靠的,用于存储文章和跟踪每个主题的文章得分。

In terms of scalability, I don't see a problem with millions of topics and posts but you'd be safer doing some back-of-the-napkin math to have a sense of stuff like the throughout you'll need and amount of memory required. Also, from the looks of it out looks that you can easily use two databases - one for posts and one for topics - to better handle potential load.

在可伸缩性方面,我不认为有数百万个主题和帖子存在问题,但是做一些粗略的数学计算会更安全一些,比如你需要的东西,以及所需的记忆量。此外,从外观来看,您可以轻松地使用两个数据库——一个用于post,一个用于主题——以更好地处理潜在的负载。

Lastly, no - if Redis isn't enough, I don't see how you'll pull this off with decent performance and scale with a SQL database.

最后,不,如果Redis还不够,我不知道如何使用SQL数据库实现出色的性能和可伸缩性能。