My Table of statistics: ?
1234567 |
CREATE TABLE events_all_time (
id
int
(11) unsigned
NOT NULL AUTO_INCREMENT,
action varchar
(255)
NOT NULL
,
count int
(11)
NOT NULL DEFAULT 0,
PRIMARY KEY (id),
UNIQUE KEY uniq_action (
action
)
);
|
The Redis commands that are ready to be executed in each row of data are as follows:?
1 |
HSET events_all_time [action] [count] |
According to the Redis command rule above, create a events_to_redis.sql file that is used to generate the Redis Data protocol format sql:?
123456789101112131415161718192021 |
-- events_to_redis.sql
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,
‘events_all_time‘ AS redis_key,
action AS hkey,
count AS hval
FROM events_all_time
)
AS t
|
OK, execute with the following command:?
1 |
mysql stats_db --skip-column-names --raw < events_to_redis.sql | redis-cli --pipe |
Important MySQL Parameter description: --raw: Make MySQL do not convert the line break in field values. --skip-column-names: Does not include the column name in each line of MySQL output. |