Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to move data from mysql to redis

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...