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.
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.
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:
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 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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.