【问题标题】:Is there a normal practice to loop through redis?循环通过redis有正常的做法吗?
【发布时间】:2021-12-30 23:16:39
【问题描述】:

我使用 redis 作为我的临时存储,我用 hSet 键填充。 我只需要存储不到 10 分钟前更新的活动会话。我决定每 10 分钟检查一次后台工作人员的所有密钥,以将非活动会话插入到我的主 PostgreSQL 中,并将其从 redis 中删除。我知道“EXPIRE”对我不起作用,因为我需要在擦除之前保存我的会话。

我正在使用节点“redis”包,我的 redis 平均有效负载约为 50 000 个活动会话。 这是解决我问题的唯一方法吗:

for await (const key of connection.scanIterator()) {
    const data = await connection.hGetAll(key);
    if (is10MinutesHasPast(data)) {
        // insert data to postgres
        await connection.delete(key)
    }
}

【问题讨论】:

    标签: node.js database optimization redis node-redis


    【解决方案1】:

    您可能想查看https://github.com/RedisGears/rgsync/tree/master/examples/postgres 后面的 SQL 使用 Redis Gears 可以做类似的事情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2021-03-14
      相关资源
      最近更新 更多