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