有没有一种简单的方法可以将 MySQL 表转换成 Redis 表?
有没有一种简单的方法可以将 mysql 表转换成 redis 等价物?
我在 MySQL 中有一个 myisam 表,它基本上用作键值存储,我想将其“移动”到 Redis,这样它会超级快。有没有简单的方法可以做到这一点?
谢谢。
Is there an easy way to turn a mysql table into a redis equivalent?
I have a myisam table in MySQL that is basically used as a key-value store that I want to "move" to Redis so it will be super fast. Is there an easy way to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是获取 mysql 表的转储并将相关数据条目解析为 redis 命令。
例如,数据转储会生成如下内容:
首先,您需要决定要在 Redis 中使用的密钥结构。一个想法是使用表作为键并将每行的 id 存储在一个集合中。
对于每个表,您需要创建一个用于保存 id 的键,我们将其称为 idx:$table。使用我们的示例,我们将创建 idx:carousel。
当我们解析文件时,我们将从第一列值中提取 id(在本例中)并将它们存储在 idx:carousel 中。此外,我们会将每个 INSERT 存储为散列。为此,我们将密钥 carousel 命名为:$id 并使用命令 hmset。示例中的第一个 INSERT 将这样存储:
hmset carousel:3 path '7.jpg' title 'Inspirar' comments 'inspiration'
这听起来可能比实际情况更复杂,但它非常简单。如果你觉得有点太难了,我愿意为你写一篇。
希望有帮助。
The easiest way is to get a dump of the mysql table and parse the relevant data entries into redis commands.
For example, a data dump would produce something like the following:
First you need to decide on the key structure you want to use in redis. One idea is to use the table as the key and store the ids of each row in a set.
For each table you would need to create a key that will hold the ids, lets call them idx:$table. Using our example we would create idx:carousel.
As we parse the file, we would pull the ids from the first column of values (in this case) and store them in idx:carousel. Also we would store each INSERT as a hash. To do this we name the key carousel:$id and use the command hmset. The first INSERT in the example would be stored like this:
hmset carousel:3 path '7.jpg' title 'Inspirar' comments 'inspiration'
It probably sounds more complicated than it actually is, but it is quite straightforward. If you think it is a little too difficult I am willing to write one for you.
Hope that helps.
我不知道有任何实用程序可以自动执行此类操作,您可能必须自己编写一个。您可以在 http://redis.io/clients 获取适合您首选语言的客户端库。
这听起来像是一项相当简单的任务,但难易程度完全取决于您对所用语言的舒适度和经验。
I don't know of any utilities that will perform such a thing automatically, you'll likely have to write one yourself. You can get a client library for your preferred language at http://redis.io/clients.
It sounds like a fairly straightforward task, but the ease will depend entirely on your comfort and experience with the language you write it in.
创建每列的 Redis 列表,并将每列的所有数据放入该列表中。并创建哈希来存储每个表的列表。例如,通过创建电子邮件、id、用户名和姓氏列表以及包含电子邮件、id、用户名的哈希值,可以将包含电子邮件、id、用户名、姓氏列的表存储在redis中。
Create Redis lists of each column and put all data of each column in that list. and make hashes to store the lists of each table. e.g. a table having columns email, id, username, surname will can be stored in redis by creating lists of email, id ,username and surname and a hashes which will contain email, id, username.