Import data cached mysql redis

Suppose the following table structure

CREATE TABLE sas_sys_app (
user_id varchar(38) DEFAULT NULL,
app_id int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Write sql file

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,
'hkey' AS redis_key,
user_id AS hkey,
app_id AS hval
FROM lumi_saas_access.sas_sys_app where company_id=64
) AS t

The import statement

mysql -uadmin -h host -p password database library --default-character-set = utf8 --skip-column-names --raw <app2redis.sql | redis-cli -h redis-host -p 6379 --pipe

Guess you like

Origin blog.51cto.com/viphyy/2438876