mysql到redis_如何将数据从mysql移动到Redis

bd96500e110b49cbb3cd949968f18be7.png

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.

解决方案

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', )\G

*************************** 1. row ***************************

`redis`('redis://@127.0.0.1/0/', 'GET', ): {

"out":

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值