将数据从Redis持久保存到用于数据存储的MongoDB [英] Persisting data from Redis to MongoDB for datastore

查看:385
本文介绍了将数据从Redis持久保存到用于数据存储的MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用频繁更新列表的应用程序。因此,例如,每个单击按钮的人都会被添加到与该按钮关联的唯一列表中。然后,我们要按按钮以降序显示并有限制的方式显示这些列表。

I have an application that makes use of frequently updated lists. So for example, every person that clicks a button, gets added to a unique list associated to that button. Then we'll want to display these lists, by button, in descending order and with a limit.

我们一直在使用MySQL和Memcache进行此操作。问题是这不能很好地工作。

We've been doing this using MySQL and Memcache. The problem is this does not work well.

我打算做的是使用Redis列表。每个按钮都将在redis中保留一个唯一的密钥,每个用户将使用 LPUSH 添加到密钥中。如果要获取最新的10个,可以使用 LRANGE 0 10

What I plan to do is use Redis lists. Each button will hold a unique key in redis, each user will be added to the key using LPUSH If we want to get the latest 10, we can use LRANGE 0 10

现在,这些按钮最终将过期,不再被主动添加或单击,但是,我们将需要历史数据。想法是一旦这些过期,我们将从Redis中获取数据并将其填充到MongoDB中。对历史数据的任何查询都将针对MongoDB。

Now, eventually these buttons will 'expire' and no longer be actively added to or clicked, however, we'll want historic data. The idea is once these expire, we will get the data from Redis and populate it to MongoDB. Any queries on the historic data, will be against the MongoDB.

有人会反对这种解决方案吗?

Would anyone suggest against this solution? Does it "make sense" to do it this way?

谢谢!

推荐答案

此解决方案很有意义,我在我的应用中执行了类似的操作。

This solution makes sense, I do something similar in my app.

需要注意的一件事,


例如,每个单击按钮的人都被添加到与该按钮相关的唯一列表中。

So for example, every person that clicks a button, gets added to a unique list associated to that button.

该列表中是否允许重复用户?如果是,请使用列表。如果不是这样,您可能希望将其与set结合使用(以进行唯一检查),但这会花费一些RAM。

Do you allow duplicate users in that list? If yes, use lists. If not, you might want to couple it with set (for unique checks), but it'll cost you some RAM.

这篇关于将数据从Redis持久保存到用于数据存储的MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆