例子是使用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