mysql批量遷移資料至redis
阿新 • • 發佈:2019-01-29
例子是使用hset,為什麼呢,因為考慮到便於刪除。
mysql_to_reds的檔案內容是這樣的:
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, 'USERVIP'
AS redis_key, c.uid AS hkey, '1' as hval FROM cpay c INNER JOIN Orders o ON c.orderid = o.orderid AND o.CurrState = 9 ) as t
然後執行mysql -h127.0.0.1 -uusername-p'password' -Ddatabase --skip-column-names --raw < mysql_to_reds.sql | redis-cli -h 127.0.0.1 -p 6379 --pipe