我正在考虑使用Redis来缓存一些用户数据快照,以加快对该数据的访问(其中一个原因是因为我的MysqL表遭受锁争用)而我正在寻找一步导入这样一个表的最佳方法(可能包含几条记录到数百万条记录):
MysqL> select * from mytable where snapshot = 1133;
+------+--------------------------+----------------+-------------------+-----------+-----------+
| id | email | name | surname | operation | snapshot |
+------+--------------------------+----------------+-------------------+-----------+-----------+
| 2989 | example-2989@example.com | fake-name-2989 | fake-surname-2989 | 2 | 1133 |
| 2990 | example-2990@example.com | fake-name-2990 | fake-surname-2990 | 10 | 1133 |
| 2992 | example-2992@example.com | fake-name-2992 | fake-surname-2992 | 5 | 1133 |
| 2993 | example-2993@example.com | fake-name-2993 | fake-surname-2993 | 5 | 1133 |
| 2994 | example-2994@example.com | fake-name-2994 | fake-surname-2994 | 9 | 1133 |
| 2995 | example-2995@example.com | fake-name-2995 | fake-surname-2995 | 7 | 1133 |
| 2996 | example-2996@example.com | fake-name-2996 | fake-surname-2996 | 1 | 1133 |
+------+--------------------------+----------------+-------------------+-----------+-----------+
进入Redis键值存储区.
我可以有很多“快照”加载到Redis中,基本的访问模式是(sql语法)
> select * from mytable where snapshot =?和id =?
这些快照也可以来自其他表,因此“每个快照的全局唯一ID”是列快照,例如:
MysqL> select * from my_other_table where snapshot = 1134;
+------+--------------------------+----------------+-------------------+-----------+-----------+
| id | email | name | surname | operation | snapshot |
+------+--------------------------+----------------+-------------------+-----------+-----------+
| 2989 | example-2989@example.com | fake-name-2989 | fake-surname-2989 | 1 | 1134 |
| 2990 | example-2990@example.com | fake-name-2990 | fake-surname-2990 | 8 | 1134 |
| 2552 | example-2552@example.com | fake-name-2552 | fake-surname-2552 | 5 | 1134 |
+------+--------------------------+----------------+-------------------+-----------+-----------+
加载到redis的快照永远不会改变,它们只能通过TTL一周使用
>有一种方法可以将这种数据(行和列)一步加载到Redis中,结合redis-cli –pipe和HMSET?
>为了存储/获取这些数据,在redis中使用的最佳模型是什么(考虑访问模式)?
我找到了redis-cli –pipe Redis Mass Insertion(以及MySQL to Redis in One Step),但是我无法找到实现我的要求的最佳方法(使用HMSET从一步中加载所有行/列,最佳redis模型)
提前致谢
克里斯蒂安.