1.编写SQL语句,把mysql数据组合成Redis协议数据流
select CONCAT("*4","\r\n","$4","\r\n","hset","\r\n$8\r\n","user_sys","\r\n","$",LENGTH(user_name),"\r\n",user_name,"\r\n","$",LENGTH(info),"\r\n",info,"\r")
from (select user_name,CONCAT('{"id":',id,',"pass":',user_pass,',"regdate":"',user_regdate,'"}') as info from user_sys limit 0,10) as t;
2.把这个sql放到linux系统下用文件保存为user_sys.sql
3.mysql -u root -p -D db --skip-column-names --raw < user_sys.sql | redis-cli --Pipe
--skip-column-names (不显示列名)
--raw(原生输出)