Redis data is only one dimensional(STRING,LIST,SET) or two
dimensional(ZSET,HASH), so transforming redis commands into Mysql
tables is actually fairly easy.
The idea of having a script that listens to the append-only file (from
Marion) DOES work, it requires some transformations, but is fairly
quick, the key is your data is organized in a way that can easily
NORMALISE.
Building transformations is not that hard: (quick & dirty writeup)
A.) STRING (created by "SET" cmd) can simple be INSERTed into a table
w/ a pk that auto-increments and two varchar(256)s named key and value
1.) "SET x 10000"-> "INSERT into STRINGS values ("x","10000"); {pk
will be 1}
2.) "SET y 20000"-> "INSERT into STRINGS values ("y","20000"); {pk
will be 2}
B.) LIST is pretty much the same except the table needs a timestamp
and LPOPs sort to last timestamp and delete.
1.) "LADD L 10" -> INSERT into LISTS ("L","10") {timestamp would be
1280349447}
2.) "LADD L 20" -> INSERT into LISTS ("L","20") {timestamp would be
1280349448}
3.) "LPOP L" -> DELETE from LISTS where name = "L" and timestamp
= (SELECT max(timestamp) from LISTS where name ="L");
C.) HASH needs two fields (key varchar(32) and value FLOAT), HDEL
needs to create a SQL DELETE with pk=x and key=k.
1.) "HADD H key1 val1" -> INSERT INTO HASHES values
("H","key1",val1");
2.) "HDEL H keys1" -> DELETE FROM HASHES where pk="H" and
key="key1"
Further complicated denormalised key-value sets can also be normalised
back into SQL
Here is an example bash script:
CLI="./redis-cli"
$CLI set user:1:name bill
$CLI set user:1:age 33
$CLI set user:1:status member
$CLI set user:2:name jane
$CLI set user:2:age 22
$CLI set user:2:status premium
Its pretty easy to dump this data, use the unix "sort" command and
insert the following rows into the following table:
#CREATE table users (id int primary key, name varchar(32), age int,
status varchar(32));
#insert into users values(1,"bill",33,"member");
#insert into users values(2,"jane",22,"premium");
So if your data is organised properly, having a script do a "tail -f
appendonly-file | ./script | mysql" will work.
The Key is to make sure your data can be NORMALISED trivially and
systematically.
Hope my explanation was not so quick and dirty that it makes sense :)
On Jul 2, 11:52 pm, Mason Jones <
masonjo...@charnel.com> wrote:
> As Jeremy asked, I'm also curious why a cron wouldn't work and why you
> say it would time out...
>
> One idea, though I'm not sure how difficult it might be (partially
> depending on your specific data) would be to set up Redis to use an
> append-only file, and write a script to read that file, parse it, and
> use it to write to MySQL. In theory I think that should work, though
> in practice...who knows.
>