One step to complete MySQL migration to Redis

Source: Internet
Author: User

Refer to the method of foreign Daniel, Http://www.oschina.net/translate/mysql-to-redis-in-one-step

The experiment was successful, and here's how to do it:

MySQL Table structure data

[test]> select * from Hechunyang;
+----+--------+---------+
| ID | MyName | Mymoney |
+----+--------+---------+
| 1 |    AA | 1000 |
| 2 |    bb | 2000 |
+----+--------+---------+
2 rows in Set (0.00 sec)


Edit a migrated SQL script

Cat Mysql_to_redis.sql
SELECT CONCAT (
"*4\r\n",
' $ ', LENGTH (redis_cmd), ' \ r \ n ',
Redis_cmd, ' \ r \ n ',
' $ ', LENGTH (redis_key), ' \ r \ n ',
Redis_key, ' \ r \ n ',
' $ ', LENGTH (hkey), ' \ r \ n ',
HKEY, ' \ r \ n ',
' $ ', LENGTH (hval), ' \ r \ n ',
Hval, ' \ R '
)
From (
SELECT
' Hset ' as Redis_cmd,
'keyname' as Redis_key,
myname As HKEY,
Mymoney As Hval
From Hechunyang
) as T;


One step to complete MySQL migration to Redis

MySQL test--skip-column-names--raw < Mysql_to_redis.sql | REDIS-CLI--pipe
All data transferred. Waiting for the last reply ...
Last reply received from server.
errors:0, Replies:2


Redis View Data
127.0.0.1:6379> keys *
1) "KeyName"
127.0.0.1:6379> Hkeys KeyName
1) "AA"
2) "BB"
127.0.0.1:6379> hget keyname AA
"1000"
127.0.0.1:6379> hget keyname BB
"2000"


This article is from the "Spring Yang Technical column" blog, please be sure to keep this source http://hcymysql.blog.51cto.com/5223301/1749526

One step to complete MySQL migration to 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.