【问题标题】:How to ensure memory consumption is not scaling with the size of the redis database如何确保内存消耗不随redis数据库的大小而扩展
【发布时间】:2015-07-06 12:40:51
【问题描述】:

我目前正在使用 Jedis 从 redis 数据库服务器获取我的数据。我需要将这些数据推送到 MySQL。 redis 服务器中有数百万条记录。使用以下语句,我可以将数据复制到一个集合中:

String pattern = "users*";//All keys starting with users
Set<String> users = jedis.keys(pattern)//Read all the keys in to set

现在我的users 集包含了所有记录。但是在 redis 数据库中可能有数百万条记录与我的模式匹配。这最终会消耗我所有的记忆。我该怎么做像下面这样的事情

for(All the keys that match my pattern){    
   Set<String> set = get current to (current+10000) records from server
   ...Code to push 10K records to MySQL...
   current = current + 10001;
}

或者请建议是否有一种优雅的方法

【问题讨论】:

  • 查看 Jedis 对 Redis 的 SCAN API 的实现。
  • @ItamarHaber 非常感谢!这有帮助

标签: mysql memory redis jedis nosql


【解决方案1】:

是的,你可以。为此使用SCAN 命令。查看Jedis Scan Test 的用法示例。

【讨论】:

  • 感谢@misterion 的帮助。
猜你喜欢
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
  • 2011-06-11
  • 1970-01-01
  • 2017-10-07
  • 1970-01-01
  • 2017-12-03
  • 1970-01-01
相关资源
最近更新 更多