zoukankan      html  css  js  c++  java
  • mysql2redis

    mysql2redis这个项目主要解决mysql数据跟redis数据同步的问题

    目前在测试环境研究这方面的应用,以下是git上面的介绍

    git入口    git安装入口

    Dependencies

    please download the dependencies below and compile/install it properly :

    create function lib_mysqludf_json_info returns string soname 'lib_mysqludf_json.so';
      create function json_array returns string soname 'lib_mysqludf_json.so';
      create function json_members returns string soname 'lib_mysqludf_json.so';
      create function json_object returns string soname 'lib_mysqludf_json.so';
      create function json_values returns string soname 'lib_mysqludf_json.so';

    Compile

    run make from the src dir directly.

      make
    

    Install redis udf

    please make sure that the lib_mysqludf_redis_v2.so has been put into the mysql plugin dir. By the way, you can examine where is the mysql plugin dir by run ''' mysql_config --plugindir '''. and then connect to your mysql server, run the following command to install the the redis udf.

    DROP FUNCTION IF EXISTS redis_servers_set_v2;
    DROP FUNCTION IF EXISTS redis_command_v2;
    DROP FUNCTION IF EXISTS free_resources;
    
    CREATE FUNCTION redis_servers_set_v2 RETURNS int SONAME "lib_mysqludf_redis_v2.so";
    CREATE FUNCTION redis_command_v2 RETURNS int SONAME "lib_mysqludf_redis_v2.so";
    CREATE FUNCTION free_resources RETURNS int SONAME "lib_mysqludf_redis_v2.so";

    Test redis udf

    connect to your mysql server, run the following command to test the the redis udf.

    select redis_command_v2("lpush","crmInboxEvents11",json_object(json_members("op","insert","value","valuettt")));
    
    select redis_servers_set_v2("192.168.0.118",6379);
    select redis_command_v2("lpush","crmInboxEvents11",json_object(json_members("op","insert","value","valuettt")));
    
    select redis_command_v2("hset","hkey","hfield",json_object(json_members("op","insert","value","valuettt")));
    
    
    select free_resources();
    select redis_servers_set_v2("192.168.0.118",6379);

    What's more

    you should create a trigger which will lpush the newly modified data to redis list juste as the following example:

    DELIMITER $$
    CREATE TRIGGER insert_trigger AFTER INSERT ON email_folder
      FOR EACH ROW BEGIN
        SET @ret=
             redis_command_v2("lpush","crmInboxEvents",
                                  json_object
                                  (
                                        json_members
                                        (
                                                "op",
                                                "insert",
                                                "value",
                                                json_object
                                                (
                                                    NEW.Id as "id",NEW.type as "type",
                                                    NEW.mailserver_id as "mailserverId",NEW.sender as "sender",
                                                    NEW.sender_name as "senderName",NEW.recevier as "recevier",
                                                    NEW.replyto as "replyto",NEW.bbemails as "bbemails",
                                                    NEW.ccemails as "ccemails",NEW.subject as "subject"
                                                )
                                            )
                                    )
                              );
      END$$
    DELIMITER ;

    安装链接

    1.先装着gi工具

     git clone https://github.com/jackeylu/mysql2redis.git 

     2.下载mysql2redis

     git clone http://github.com/redis/hiredis

    3.下载hiredis

    git clone http://github.com/redis/hiredis

    4.安装hiredis

    cd hiredis
    
    make && make install

    5.安装mysql2redis

    5.1.cp /usr/local/mysql/bin/mysql_config /usr/bin/ 
    


    解决方案:修改src/lib_mysqludf_redis.c下面的285行,将ld修改成lld。

    ERROR 1126 (HY000) at line 20: Can't open shared library 'lib_mysqludf_redis.so' (errno: 0 libhiredis.so.0.10: cannot open shared object file: No such file or directory)

    解决方案:运行

     sudo /sbin/ldconfig
     
  • 相关阅读:
    netcore一键部署到linux服务器以服务方式后台运行
    查找100-999之间的水仙花数
    shell创建数据库的脚本
    python打印九九乘法表的菱形实现
    c++一些重要的细节
    MySQL数据库基础学习笔记(二)
    MySQL数据库基础学习笔记(一)
    react-redux 的基本使用
    react-router-dom基本使用+3种传参方式
    从create-react-app 项目搭建开始
  • 原文地址:https://www.cnblogs.com/fangyuan303687320/p/5282482.html
Copyright © 2011-2022 走看看