将Redis数据移至MySQL的更快方法 [英] The faster method to move redis data to MySQL

查看:284
本文介绍了将Redis数据移至MySQL的更快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有大型的购物和产品交易系统.我们在使用MySQL时遇到了很多问题,因此经过很少的研发,我们计划使用Redis,并开始将Redis集成到我们的系统中. 在此之前直接访问数据库之后,现在我们移动了Redis系统

We have big shopping and product dealing system. We have faced lots problem with MySQL so after few r&D we planned to use Redis and we start integrating Redis in our system. Following this previously directly hitting the database now we have moved the Redis system

  1. 用户购物车详细信息
  2. 会员点击跟踪记录
  3. 我们有产品交易用户数据.
  4. 其他网站统计信息.

我不仅将数据存储在Redis系统中,而且还编写了可以在一定时间间隔将Redis数据移动到MySQL数据中的cron.这是我面临的问题的重点. 波纹管点我在寻找解决方案

I am not only storing the data in Redis system i have written crons which moves Redis data in MySQL data at time intervals. This is the main point i am facing the issues. Bellow points i am looking for solution

  1. 他们还有其他将Redis大数据转储到MySQL的方法吗?
  2. Redis无法将我们的数据存储在文件中,因此可以将这些数据直接存储到MySQL数据库吗?
  3. Redis是否使用任何可以避免队列系统之类的触发器的触发系统?

推荐答案

是将Redis大数据转储到MySQL的其他方法吗?

Redis可以(使用bgsave)以非阻塞且一致的方式生成数据转储.

Redis has the possibility (using bgsave) to generate a dump of the data in a non blocking and consistent way.

https://github.com/sripathikrishnan/redis-rdb-tools

您可以使用Sripathi Krishnan的著名软件包在Python中解析redis转储文件(RDB),然后离线填充MySQL实例.或者,您可以将Redis转储转换为JSON格式,并以您想要填充MySQL的任何语言编写脚本.

You could use Sripathi Krishnan's well-known package to parse a redis dump file (RDB) in Python, and populate the MySQL instance offline. Or you can convert the Redis dump to JSON format, and write scripts in any language you want to populate MySQL.

仅当您要将Redis实例的完整数据复制到MySQL中时,此解决方案才有意义.

This solution is only interesting if you want to copy the complete data of the Redis instance into MySQL.

Redis是否有任何触发系统可用于避免队列系统之类的笨蛋?

Redis没有触发器的概念,但是每次必须将某些内容复制到MySQL时,都不会阻止您将事件发布到Redis队列中.例如,代替:

Redis has no trigger concept, but nothing prevents you to post events in Redis queues each time something must be copied to MySQL. For instance, instead of:

# Add an item to a user shopping cart
RPUSH user:<id>:cart <item>

您可以执行:

# Add an item to a user shopping cart
MULTI
RPUSH user:<id>:cart <item>
RPUSH cart_to_mysql <id>:<item>
EXEC

MULTI/EXEC块使其具有原子性和一致性.然后,您只需要编写一个小程序,就可以在cart_to_mysql队列的项目上等待(使用BLPOP命令).对于每个出队项目,守护程序必须从Redis获取相关数据,并填充MySQL实例.

The MULTI/EXEC block makes it atomic and consistent. Then you just have to write a little daemon waiting on items of the cart_to_mysql queue (using BLPOP commands). For each dequeued item, the daemon has to fetch the relevant data from Redis, and populate the MySQL instance.

Redis无法将我们的数据存储在文件中,因此可以将这些数据直接存储到MySQL数据库吗?

我不确定我是否理解这里的问题.但是,如果使用上述解决方案,则Redis更新和MySQL更新之间的延迟将非常有限.因此,如果Redis失败,您将只松散最后的操作(与基于cron作业的解决方案相反).当然,在数据的传播中不可能具有100%的一致性.

I'm not sure I understand the question here. But if you use the above solution, the latency between Redis updates and MySQL updates will be quite limited. So if Redis fails, you will only loose the very last operations (contrary to a solution based on cron jobs). It is of course not possible to have 100% consistency in the propagation of data though.

这篇关于将Redis数据移至MySQL的更快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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