msyql 同步管道方式快速匯入redis

最閒的碼農發表於2020-08-09

mac or liunx 使用 \r\n win 使用 \n

SELECT CONCAT(
   "*8\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',hval3
)FROM(
   SELECT 'HSET' AS redis_cmd,
   concat_ws(':','users', id) AS redis_key,
   'id' AS hkey1, id AS hval1,
   'name' AS hkey2, name AS hval2,
   'score' AS hkey3, age AS hval3
   From users
)AS t

執行

 mysql -uroot -p123456 -Dtest --default-character-set=utf8 --skip-column-names --raw < test.sql | redis-cli --pipe

msyql 同步管道方式快速匯入redis

本作品採用《CC 協議》,轉載必須註明作者和本文連結

七述

相關文章