Is there an easy way to turn a MySQL table into a Redis equivalent?

Is there an easy way to turn a mysql table into a redis equivalent?

I have a myisam table in MySQL, which is mainly used as a storage of key values, which I want to "move" to Redis, so it will be very fast. Is there an easy way to do this?

Thanks.

+7
source share
3 answers

The easiest way is to get a mysql table dump and parse the corresponding data records into redis commands.

For example, a data dump will create something like the following:

CREATE TABLE carousel( id int(11), path varchar(200), title varchar(200), comments varchar(200) ); INSERT INTO carousel VALUES (3,'7.jpg','Inspirar','inspiration'); INSERT INTO carousel VALUES (4,'d.jpg','Pilotar','pilotar'); INSERT INTO carousel VALUES (5,'8.jpg','Sentir','sentir'); INSERT INTO carousel VALUES (6,'6.jpg','Volar','volar'); 

First you need to decide on the key structure that you want to use in redis. One idea is to use the table as a key and store the identifiers of each row in the set.

For each table you need to create a key that will contain identifiers, allows you to call them idx: $ table. Using our example, we will create idx: carousel.

When analyzing the file, we pull out the identifiers from the first column of values ​​(in this case) and save them in idx: carousel. We will also store each INSERT as a hash. To do this, we will call the key carousel: $ id and use the hmset command. The first INSERT in the example will be stored as follows:

hmset carousel: 3 way '7.jpg' name 'inspiration' comments 'inspiration'

It probably sounds more complicated than it really is, but it's pretty simple. If you think this is too complicated, I am ready to write for you.

Hope this helps.

+8
source

I do not know any utilities that will perform such a thing automatically; you will probably have to write it yourself. You can get the client library in your preferred language http://redis.io/clients .

This sounds like a fairly simple task, but the ease will depend entirely on your comfort and experience with the language in which you write it.

0
source

Create Redis lists of each column and put all the data of each column in this list. and make hashes to store lists of each table. for example, a table with columns of email, identifier, username, last name will be saved in redis by creating lists of email, identifier, username and last name and hashes that will contain the email address, identifier, username.

0
source

All Articles