Reputation: 67
I attempt to put some frequently used data into redis server from mysql . so redis just as a read server , i need to move data from mysql to redis. can anybody recommend a good approache ? i have read some topics and have some thinking share
1、through mysql trigger to record proper data , through timing app move data to redis 2、read mysql logs ,analysis it ,then put it to redis.
BTW: in my application data stored in redis don't need real-time, a little latency is ok.
Upvotes: 5
Views: 6495
Reputation: 829
I think the mysql udf plugin (https://github.com/Ideonella-sakaiensis/lib_mysqludf_redis) can help you to synchronize data from Mysql to Redis.
example:
DELIMITER $$
CREATE TABLE `my_table` (
id varchar(16) PRIMARY KEY,
text varchar(32)
);
set up a trigger for the table and call redis command by mysql udf
DELIMITER $$
CREATE TRIGGER `after_insert_my_table`
AFTER INSERT ON `my_table` FOR EACH ROW
BEGIN
DO `redis`('redis://@127.0.0.1/0/', 'SET', new.`id`, new.`text`);
END $$
DELIMITER ;
then you can get value by my_table id
mysql> SELECT `redis`('redis://@127.0.0.1/0/', 'GET', <my_table id>)\G
*************************** 1. row ***************************
`redis`('redis://@127.0.0.1/0/', 'GET', <my_table id>): {
"out": <my_table text>
}
Upvotes: 2
Reputation: 3121
Use mass-insert mode of redis-cli.
Check this out - http://dcw.ca/blog/2013/01/02/mysql-to-redis-in-one-step/
Upvotes: 0