MySQL Synchronous Redis

Source: Internet
Author: User

The official plugin   https://github.com/dawnbreaks/mysql2redis installs the plugin   and relies on//  installation apr + apr-util$  wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.gz$ tar zxvf  Apr-1.5.1.tar.gz$ ./configure --prefix=/usr/local/apr$ make$ make install$ wget  http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz$ cd apr-util-1.5.4$ ./ configure --with-apr=/usr/local/apr$ make$ make install//  installation hiredis,  Redis's C language client$ git clone https://github.com/redis/hiredis$ cd hiredis$ make$  make install$ git clone https://github.com/dawnbreaks/mysql2redis.git$ cd  mysql2redis$ make$ cp lib_mysqludf_redis_v2.so /usr/lib64/mysql/plugin/first to the correctness of the dynamic library   Otherwise the registration function will be error-bash-4.1# ldd /usr/local/mysql/lib/plugin/lib_mysqludf_redis_v2.so          linux-vdso.so.1 =>   (0x00007fff98f5a000)         libhiredis.so.0.13 = > /usr/local/lib/libhiredis.so.0.13  (0x00007f255127e000)          libapr-1.so.0 => /usr/lib64/libapr-1.so.0  (0x00007f2551051000)          libaprutil-1.so.0 => /usr/lib64/libaprutil-1.so.0  ( 0x00007f2550e2d000)         libc.so.6 => /lib64/libc.so.6   (0x00007f2550a99000)         libuuid.so.1 => /lib64/ libuuid.so.1  (0x00007f2550895000)         libcrypt.so.1 =>  /lib64/libcrypt.so.1  (0x00007f255065d000)          libpthread.so.0 => /lib64/libpthread.so.0  (0x00007f2550440000)          libexpat.so.1 => /lib64/libexpat.so.1  (0x00007f2550218000)          libdb-4.7.so => /lib64/libdb-4.7.so  (0x00007f254fea3000)          /lib64/ld-linux-x86-64.so.2  (0x00000038c2800000)          libfreebl3.so => /lib64/libfreebl3.so  (0x00007f254fc2c000)          libdl.so.2 => /lib64/libdl.so.2  (0x00007f254fa28000)                   ensure that there are no errors and then register   MYSQ2REDIS UDF's function 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"; Now, let's start building tables in the database.Test      We'll start with a new table in Tset     CREATE TABLE  ' User_info '   (    ' id '  int (+)  NOT NULL,   ' NAME '  varchar (255)  collate utf8_ unicode_ci default null,   ' age '  varchar (one)  COLLATE utf8_unicode_ci  default null,   ' email '  varchar (255)  COLLATE utf8_unicode_ci DEFAULT  null,   ' addr '  varchar (255)  COLLATE utf8_unicode_ci DEFAULT NULL,   PRIMARY KEY  (' id '))  engine=innodb default charset=utf8 collate=utf8_ unicode_ci;   then new   a insert  with upudate trigger  CREATE TRIGGER  ' Trigger_insert '  AFTER INSERT ON  ' user_info '  FOR EACH ROW BEGINSET  @ret = (select  REDIS_SERVERS_SET_V2 ("6.6.6.6", 6379)); set  @ret1 = (SELECT REDIS_COMMAND_V2 ("Hmset",  Concat ("User_info:",  id), ' Name ', name,  ' age ', age,  ' email ', email,  ' addr ',  addr '  from user _info where id = new.id); end; create trigger  ' trigger_update '  AFTER UPDATE ON  ' User_info '  for each  ROW BEGINSET  @ret = (SELECT REDIS_SERVERS_SET_V2 ("6.6.6.6", 6379); set  @ret1 = ( SELECT REDIS_COMMAND_V2 ("Hmset",  concat ("User_info:",  id),  ' name ', name,  ' age ',  age,  ' email ', email,  ' addr ',  addr)  from user_info where id  = old.id); end; As for the contents of the trigger does not understand can go to Baidu here do not explain to see the test results first situation redis  inside the data 6.6.6.6:6379> flushallok6.6.6.6 : 6379> keys * (Empty list or set) inserts data into the database mysql> truncate table  user_info;  #  Clear Table Data query ok, 0 rows affected  (0.04 SEC) mysql>  INSERT INTO  ' User_info '  VALUES  (1,  ' 111 ',  26,  ' [email protected] ',  ' 1111  '); query   mysqlmysql> select * from  user_info;+----+------+------+-------------+-------+| id | name | age   | email       | addr  |+----+------+------+------ -------+-------+|  1 | 111  | 26   | [email  protected] | 1111  |+----+------+------+-------------+-------+1 row in set   (0.00 SEC) mysql>  for query  redis6.6.6.6:6379> keys * (empty list or  set) 6.6.6.6:6379> keys *1)   "User_info:1" 6.6.6.6:6379> hgetall user_info : one)   "name" 2)   "111" 3)   "age" 4)   "5"   "email" 6)   "[email protected]" 7)   " Addr "8)  " 1111  "6.6.6.6:6379>  here, we're done with the configuration.


This article from the "Believe it or not you" blog, reproduced please contact the author!

MySQL Synchronous Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.