MySQL data to Redis quick Import

Source: Internet
Author: User

Redis protocol

*<args><cr><lf> number of parameters $<len><cr><lf> first parameter length <arg0><cr><lf> The first parameter $<len><cr><lf> the first parameter length <arg1><cr><lf> the second parameter ...

Write SQL statements that combine MySQL data into Redis protocol data streams

Select CONCAT ("*16\r\n", ' $ ', Length (redis_cmd), ' \ r \ n ', Redis_cmd, ' \ r \ n ', ' $ ', Length (redis_key), ' \ r \ n ', Redis_key, ' \ r\n ', ' $ ', Length (hkey1), ' \ r \ n ', Hkey1, ' \ r \ n ', ' $ ', Length (hval1), ' \ r \ n ', Hval1, ' \ r \ n ' $ ', Length (hkey2), ' \ r \ n ', Hkey2 , ' \ r \ n ', ' $ ', Length (hval2), ' \ r \ n ', Hval2, ' \ r \ n ' $ ', Length (hkey3), ' \ r \ n ', Hkey3, ' \ r \ n ', ' $ ', Length (hval3), ' \ r \ n ', HV Al3, ' \ r \ n ' $ ', Length (hkey4), ' \ r \ n ', Hkey4, ' \ r \ n ', ' $ ', Length (hval4), ' \ r \ n ', Hval4, ' \ r \ n ', ' $ ', Length (hkey5), ' \ r \ n ', Hkey5, ' \ r \ n ', ' $ ', Length (HVAL5), ' \ r \ n ', HVAL5, ' \ r \ n ' $ ', Length (hkey6), ' \ r \ n ', Hkey6, ' \ r \ n ', ' $ ', Length (hval6), ' \r\ N ', hval6, ' \ r \ n ' ' $ ', Length (hkey7), ' \ r \ n ', Hkey7, ' \ r \ n ', ' $ ', LENGTH (hval7), ' \ r \ n ', Hval7, ' \ R ') from (SELECT ' Hmset ' as Redis_cmd, CONCAT (resource_id, ' _hash ') as Redis_key, ' name ' as hkey1,resource_title as Hval1, ' type ' as Hkey2,resource_ Type_name as Hval2, ' exe ' as hkey3,resource_format as Hval3, ' page ' as hkey4,resource_page as Hval4, ' size ' as Hkey5,resource _size as HVAL5, ' time ' as Hkey6,create_time as hval6, ' num ' as hkey7,resource_downcount as Hval7 from T_resource_info) as T 

Spell out the string

Definition of *16\r\n$5\r\nhmset\r\n$9\r\nnba231058\r\n$4\r\nname\r\n$51\r\n green food and the use of green food sign \r\n$4\r\ntype\r\n$6\r\n text \r\n$ 3\r\nexe\r\n$3\r\ndoc\r\n$4\r\npage\r\n$1\r\n1\r\n$4\r\nsize\r\n$6\r\n79.5kb\r\n$4\r\ntime\r\n$19\r\ N2013-05-31 08:56:59\r\n$3\r\nnum\r\n$2\r\n18\r\n

Execute the following statement

Mysql-h 10.10.3.218-uroot-p123456-dtest_db--skip-column-names--raw </usr/local/redis.sql |redis-cli--pipe

–raw: Make MySQL do not convert the line break in field values.
–skip-column-names: Does not include the column name in each line of MySQL output.

performed separately

Echo-en ' *3\r\n$3\r\nset\r\n$3\r\nkey\r\n$5\r\nvalue\r\n ' | REDIS-CLI--pipe

Tested 200W data, can be completed within 2 minutes.

MySQL data to Redis quick Import

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.