# #创建表及数据
CREATE TABLE Events_all_time (
ID int (one) unsigned not NULL auto_increment,
Action varchar (255) is not NULL,
Count Int (one) is not NULL DEFAULT 0,
PRIMARY KEY (ID),
UNIQUE KEY uniq_action (action)
);
Insert into Events_all_time (Action,count) VALUES (' Yangdan ', 1000);
Insert into Events_all_time (Action,count) VALUES (' Liufeng ', 200);
# #保存同步数据脚本
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;
# #执行同步命令 (Shell)
MySQL [-H 127.0.0.1]-uroot-plinuxcast-dtestredis--skip-column-names--raw </usr/local/events_to_redis.sql | REDIS-CLI--pipe
# #登录redis
Hgetall Events_all_time
This article is from the "Little Dog Blog" blog, please be sure to keep this source http://9196589.blog.51cto.com/9186589/1728650
MySQL synchronizes data to Redis